Record schema namespace since there are at least 2. [not part of build]

This commit is contained in:
vidur%netscape.com 2002-01-09 01:26:22 +00:00
Родитель fea61336ed
Коммит 410fb06eef
12 изменённых файлов: 76 добавлений и 66 удалений

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

@ -67,6 +67,8 @@ interface nsISchemaComponent : nsISupports {
[scriptable, uuid(3c14a021-6f4e-11d5-9b46-000064657374)] [scriptable, uuid(3c14a021-6f4e-11d5-9b46-000064657374)]
interface nsISchema : nsISchemaComponent { interface nsISchema : nsISchemaComponent {
readonly attribute AString schemaNamespace;
readonly attribute PRUint32 typeCount; readonly attribute PRUint32 typeCount;
nsISchemaType getTypeByIndex(in PRUint32 index); nsISchemaType getTypeByIndex(in PRUint32 index);
nsISchemaType getTypeByName(in AString name); nsISchemaType getTypeByName(in AString name);

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

@ -29,8 +29,9 @@
// //
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
nsSchema::nsSchema(nsISchemaCollection* aCollection, nsSchema::nsSchema(nsISchemaCollection* aCollection,
const nsAReadableString& aTargetNamespace) const nsAReadableString& aTargetNamespace,
: mTargetNamespace(aTargetNamespace) const nsAReadableString& aSchemaNamespace)
: mTargetNamespace(aTargetNamespace), mSchemaNamespace(aSchemaNamespace)
{ {
NS_INIT_ISUPPORTS(); NS_INIT_ISUPPORTS();
mCollection = aCollection; // Weak reference mCollection = aCollection; // Weak reference
@ -51,6 +52,14 @@ nsSchema::GetTargetNamespace(nsAWritableString& aTargetNamespace)
return NS_OK; return NS_OK;
} }
/* readonly attribute wstring schemaNamespace; */
NS_IMETHODIMP
nsSchema::GetSchemaNamespace(nsAWritableString& aSchemaNamespace)
{
aSchemaNamespace.Assign(mSchemaNamespace);
return NS_OK;
}
/* void resolve (); */ /* void resolve (); */
NS_IMETHODIMP NS_IMETHODIMP
nsSchema::Resolve() nsSchema::Resolve()

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

@ -493,7 +493,7 @@ nsSchemaLoader::GetType(const nsAReadableString & aName,
nsISchemaType **_retval) nsISchemaType **_retval)
{ {
if (IsSchemaNamespace(aNamespace)) { if (IsSchemaNamespace(aNamespace)) {
return GetBuiltinType(aName, _retval); return GetBuiltinType(aName, aNamespace, _retval);
} }
if (IsSOAPNamespace(aNamespace)) { if (IsSOAPNamespace(aNamespace)) {
@ -681,10 +681,11 @@ nsSchemaLoader::ProcessSchemaElement(nsIDOMElement *element,
nsresult rv = NS_OK; nsresult rv = NS_OK;
// Get target namespace and create the schema instance // Get target namespace and create the schema instance
nsAutoString targetNamespace; nsAutoString targetNamespace, schemaNamespace;
element->GetAttribute(NS_LITERAL_STRING("targetNamespace"), element->GetAttribute(NS_LITERAL_STRING("targetNamespace"),
targetNamespace); targetNamespace);
nsSchema* schemaInst = new nsSchema(this, targetNamespace); element->GetNamespaceURI(schemaNamespace);
nsSchema* schemaInst = new nsSchema(this, targetNamespace, schemaNamespace);
nsCOMPtr<nsISchema> schema = schemaInst; nsCOMPtr<nsISchema> schema = schemaInst;
if (!schema) { if (!schema) {
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
@ -807,7 +808,7 @@ nsSchemaLoader::GetSOAPType(const nsAReadableString& aName,
nsresult rv = NS_OK; nsresult rv = NS_OK;
nsAutoString concat(aNamespace); nsAutoString concat(aNamespace);
concat.Append(aName); concat.Append(aName);
nsStringKey key(aName); nsStringKey key(concat);
nsCOMPtr<nsISupports> sup = dont_AddRef(mSOAPTypeHash.Get(&key)); nsCOMPtr<nsISupports> sup = dont_AddRef(mSOAPTypeHash.Get(&key));
if (sup) { if (sup) {
rv = CallQueryInterface(sup, aType); rv = CallQueryInterface(sup, aType);
@ -845,10 +846,13 @@ nsSchemaLoader::GetSOAPType(const nsAReadableString& aName,
nsresult nsresult
nsSchemaLoader::GetBuiltinType(const nsAReadableString& aName, nsSchemaLoader::GetBuiltinType(const nsAReadableString& aName,
const nsAReadableString& aNamespace,
nsISchemaType** aType) nsISchemaType** aType)
{ {
nsresult rv = NS_OK; nsresult rv = NS_OK;
nsStringKey key(aName); nsAutoString concat(aName);
concat.Append(aNamespace);
nsStringKey key(concat);
nsCOMPtr<nsISupports> sup = dont_AddRef(mBuiltinTypesHash.Get(&key)); nsCOMPtr<nsISupports> sup = dont_AddRef(mBuiltinTypesHash.Get(&key));
if (sup) { if (sup) {
rv = CallQueryInterface(sup, aType); rv = CallQueryInterface(sup, aType);
@ -996,7 +1000,8 @@ nsSchemaLoader::GetBuiltinType(const nsAReadableString& aName,
return NS_ERROR_SCHEMA_UNKNOWN_TYPE; return NS_ERROR_SCHEMA_UNKNOWN_TYPE;
} }
nsSchemaBuiltinType* builtin = new nsSchemaBuiltinType(typeVal); nsSchemaBuiltinType* builtin = new nsSchemaBuiltinType(typeVal,
aNamespace);
if (!builtin) { if (!builtin) {
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
} }
@ -1042,26 +1047,6 @@ nsSchemaLoader::GetNewOrUsedType(nsSchema* aSchema,
} }
} }
#if 0
if (namespaceURI.Length() > 0) {
if (IsSchemaNamespace(namespaceURI)) {
return GetBuiltinType(localName, aType);
}
// XXX Currently we only understand the schema namespace or the
// target namspace. When we start dealing with includes and imports,
// we can search for types in other namespaces.
nsAutoString targetNamespace;
aSchema->GetTargetNamespace(targetNamespace);
if (!namespaceURI.Equals(targetNamespace)) {
return NS_ERROR_SCHEMA_UNKNOWN_TARGET_NAMESPACE;
}
}
// We don't have a namespace, so get the local type
rv = aSchema->GetTypeByName(localName, aType);
#endif
// If we didn't get a type, we need to create a placeholder // If we didn't get a type, we need to create a placeholder
if (NS_SUCCEEDED(rv) && !*aType) { if (NS_SUCCEEDED(rv) && !*aType) {
nsSchemaTypePlaceholder* placeholder = new nsSchemaTypePlaceholder(aSchema, nsSchemaTypePlaceholder* placeholder = new nsSchemaTypePlaceholder(aSchema,
@ -1174,7 +1159,10 @@ nsSchemaLoader::ProcessElement(nsSchema* aSchema,
} }
if (!schemaType) { if (!schemaType) {
nsAutoString ns;
aElement->GetNamespaceURI(ns);
rv = GetBuiltinType(NS_LITERAL_STRING("anyType"), rv = GetBuiltinType(NS_LITERAL_STRING("anyType"),
ns,
getter_AddRefs(schemaType)); getter_AddRefs(schemaType));
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
return rv; return rv;

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

@ -216,6 +216,7 @@ protected:
const nsAReadableString& aTypeName, const nsAReadableString& aTypeName,
nsISchemaType** aType); nsISchemaType** aType);
nsresult GetBuiltinType(const nsAReadableString& aName, nsresult GetBuiltinType(const nsAReadableString& aName,
const nsAReadableString& aNamespace,
nsISchemaType** aType); nsISchemaType** aType);
nsresult GetSOAPType(const nsAReadableString& aName, nsresult GetSOAPType(const nsAReadableString& aName,
const nsAReadableString& aNamespace, const nsAReadableString& aNamespace,

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

@ -43,7 +43,8 @@ class nsSchema : public nsISchema
{ {
public: public:
nsSchema(nsISchemaCollection* aCollection, nsSchema(nsISchemaCollection* aCollection,
const nsAReadableString& aTargetNamespace); const nsAReadableString& aTargetNamespace,
const nsAReadableString& aSchemaNamespace);
virtual ~nsSchema(); virtual ~nsSchema();
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
@ -61,6 +62,7 @@ public:
protected: protected:
nsString mTargetNamespace; nsString mTargetNamespace;
nsString mSchemaNamespace;
nsSupportsArray mTypes; nsSupportsArray mTypes;
nsSupportsHashtable mTypesHash; nsSupportsHashtable mTypesHash;
nsSupportsArray mAttributes; nsSupportsArray mAttributes;
@ -98,7 +100,8 @@ protected:
class nsSchemaBuiltinType : public nsISchemaBuiltinType class nsSchemaBuiltinType : public nsISchemaBuiltinType
{ {
public: public:
nsSchemaBuiltinType(PRUint16 aBuiltinType); nsSchemaBuiltinType(PRUint16 aBuiltinType,
const nsAReadableString& aName);
virtual ~nsSchemaBuiltinType(); virtual ~nsSchemaBuiltinType();
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
@ -109,6 +112,7 @@ public:
protected: protected:
PRUint16 mBuiltinType; PRUint16 mBuiltinType;
nsString mNamespace;
}; };
class nsSchemaListType : public nsSchemaComponentBase, class nsSchemaListType : public nsSchemaComponentBase,

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

@ -28,8 +28,9 @@
// nsSchemaBuiltinType implementation // nsSchemaBuiltinType implementation
// //
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
nsSchemaBuiltinType::nsSchemaBuiltinType(PRUint16 aBuiltinType) nsSchemaBuiltinType::nsSchemaBuiltinType(PRUint16 aBuiltinType,
: mBuiltinType(aBuiltinType) const nsAReadableString& aNamespace)
: mBuiltinType(aBuiltinType), mNamespace(aNamespace)
{ {
NS_INIT_ISUPPORTS(); NS_INIT_ISUPPORTS();
} }
@ -48,7 +49,7 @@ NS_IMPL_ISUPPORTS4_CI(nsSchemaBuiltinType,
NS_IMETHODIMP NS_IMETHODIMP
nsSchemaBuiltinType::GetTargetNamespace(nsAWritableString& aTargetNamespace) nsSchemaBuiltinType::GetTargetNamespace(nsAWritableString& aTargetNamespace)
{ {
aTargetNamespace.Assign(NS_LITERAL_STRING(NS_SCHEMA_2001_NAMESPACE)); aTargetNamespace.Assign(mNamespace);
return NS_OK; return NS_OK;
} }

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

@ -67,6 +67,8 @@ interface nsISchemaComponent : nsISupports {
[scriptable, uuid(3c14a021-6f4e-11d5-9b46-000064657374)] [scriptable, uuid(3c14a021-6f4e-11d5-9b46-000064657374)]
interface nsISchema : nsISchemaComponent { interface nsISchema : nsISchemaComponent {
readonly attribute AString schemaNamespace;
readonly attribute PRUint32 typeCount; readonly attribute PRUint32 typeCount;
nsISchemaType getTypeByIndex(in PRUint32 index); nsISchemaType getTypeByIndex(in PRUint32 index);
nsISchemaType getTypeByName(in AString name); nsISchemaType getTypeByName(in AString name);

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

@ -29,8 +29,9 @@
// //
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
nsSchema::nsSchema(nsISchemaCollection* aCollection, nsSchema::nsSchema(nsISchemaCollection* aCollection,
const nsAReadableString& aTargetNamespace) const nsAReadableString& aTargetNamespace,
: mTargetNamespace(aTargetNamespace) const nsAReadableString& aSchemaNamespace)
: mTargetNamespace(aTargetNamespace), mSchemaNamespace(aSchemaNamespace)
{ {
NS_INIT_ISUPPORTS(); NS_INIT_ISUPPORTS();
mCollection = aCollection; // Weak reference mCollection = aCollection; // Weak reference
@ -51,6 +52,14 @@ nsSchema::GetTargetNamespace(nsAWritableString& aTargetNamespace)
return NS_OK; return NS_OK;
} }
/* readonly attribute wstring schemaNamespace; */
NS_IMETHODIMP
nsSchema::GetSchemaNamespace(nsAWritableString& aSchemaNamespace)
{
aSchemaNamespace.Assign(mSchemaNamespace);
return NS_OK;
}
/* void resolve (); */ /* void resolve (); */
NS_IMETHODIMP NS_IMETHODIMP
nsSchema::Resolve() nsSchema::Resolve()

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

@ -493,7 +493,7 @@ nsSchemaLoader::GetType(const nsAReadableString & aName,
nsISchemaType **_retval) nsISchemaType **_retval)
{ {
if (IsSchemaNamespace(aNamespace)) { if (IsSchemaNamespace(aNamespace)) {
return GetBuiltinType(aName, _retval); return GetBuiltinType(aName, aNamespace, _retval);
} }
if (IsSOAPNamespace(aNamespace)) { if (IsSOAPNamespace(aNamespace)) {
@ -681,10 +681,11 @@ nsSchemaLoader::ProcessSchemaElement(nsIDOMElement *element,
nsresult rv = NS_OK; nsresult rv = NS_OK;
// Get target namespace and create the schema instance // Get target namespace and create the schema instance
nsAutoString targetNamespace; nsAutoString targetNamespace, schemaNamespace;
element->GetAttribute(NS_LITERAL_STRING("targetNamespace"), element->GetAttribute(NS_LITERAL_STRING("targetNamespace"),
targetNamespace); targetNamespace);
nsSchema* schemaInst = new nsSchema(this, targetNamespace); element->GetNamespaceURI(schemaNamespace);
nsSchema* schemaInst = new nsSchema(this, targetNamespace, schemaNamespace);
nsCOMPtr<nsISchema> schema = schemaInst; nsCOMPtr<nsISchema> schema = schemaInst;
if (!schema) { if (!schema) {
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
@ -807,7 +808,7 @@ nsSchemaLoader::GetSOAPType(const nsAReadableString& aName,
nsresult rv = NS_OK; nsresult rv = NS_OK;
nsAutoString concat(aNamespace); nsAutoString concat(aNamespace);
concat.Append(aName); concat.Append(aName);
nsStringKey key(aName); nsStringKey key(concat);
nsCOMPtr<nsISupports> sup = dont_AddRef(mSOAPTypeHash.Get(&key)); nsCOMPtr<nsISupports> sup = dont_AddRef(mSOAPTypeHash.Get(&key));
if (sup) { if (sup) {
rv = CallQueryInterface(sup, aType); rv = CallQueryInterface(sup, aType);
@ -845,10 +846,13 @@ nsSchemaLoader::GetSOAPType(const nsAReadableString& aName,
nsresult nsresult
nsSchemaLoader::GetBuiltinType(const nsAReadableString& aName, nsSchemaLoader::GetBuiltinType(const nsAReadableString& aName,
const nsAReadableString& aNamespace,
nsISchemaType** aType) nsISchemaType** aType)
{ {
nsresult rv = NS_OK; nsresult rv = NS_OK;
nsStringKey key(aName); nsAutoString concat(aName);
concat.Append(aNamespace);
nsStringKey key(concat);
nsCOMPtr<nsISupports> sup = dont_AddRef(mBuiltinTypesHash.Get(&key)); nsCOMPtr<nsISupports> sup = dont_AddRef(mBuiltinTypesHash.Get(&key));
if (sup) { if (sup) {
rv = CallQueryInterface(sup, aType); rv = CallQueryInterface(sup, aType);
@ -996,7 +1000,8 @@ nsSchemaLoader::GetBuiltinType(const nsAReadableString& aName,
return NS_ERROR_SCHEMA_UNKNOWN_TYPE; return NS_ERROR_SCHEMA_UNKNOWN_TYPE;
} }
nsSchemaBuiltinType* builtin = new nsSchemaBuiltinType(typeVal); nsSchemaBuiltinType* builtin = new nsSchemaBuiltinType(typeVal,
aNamespace);
if (!builtin) { if (!builtin) {
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
} }
@ -1042,26 +1047,6 @@ nsSchemaLoader::GetNewOrUsedType(nsSchema* aSchema,
} }
} }
#if 0
if (namespaceURI.Length() > 0) {
if (IsSchemaNamespace(namespaceURI)) {
return GetBuiltinType(localName, aType);
}
// XXX Currently we only understand the schema namespace or the
// target namspace. When we start dealing with includes and imports,
// we can search for types in other namespaces.
nsAutoString targetNamespace;
aSchema->GetTargetNamespace(targetNamespace);
if (!namespaceURI.Equals(targetNamespace)) {
return NS_ERROR_SCHEMA_UNKNOWN_TARGET_NAMESPACE;
}
}
// We don't have a namespace, so get the local type
rv = aSchema->GetTypeByName(localName, aType);
#endif
// If we didn't get a type, we need to create a placeholder // If we didn't get a type, we need to create a placeholder
if (NS_SUCCEEDED(rv) && !*aType) { if (NS_SUCCEEDED(rv) && !*aType) {
nsSchemaTypePlaceholder* placeholder = new nsSchemaTypePlaceholder(aSchema, nsSchemaTypePlaceholder* placeholder = new nsSchemaTypePlaceholder(aSchema,
@ -1174,7 +1159,10 @@ nsSchemaLoader::ProcessElement(nsSchema* aSchema,
} }
if (!schemaType) { if (!schemaType) {
nsAutoString ns;
aElement->GetNamespaceURI(ns);
rv = GetBuiltinType(NS_LITERAL_STRING("anyType"), rv = GetBuiltinType(NS_LITERAL_STRING("anyType"),
ns,
getter_AddRefs(schemaType)); getter_AddRefs(schemaType));
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
return rv; return rv;

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

@ -216,6 +216,7 @@ protected:
const nsAReadableString& aTypeName, const nsAReadableString& aTypeName,
nsISchemaType** aType); nsISchemaType** aType);
nsresult GetBuiltinType(const nsAReadableString& aName, nsresult GetBuiltinType(const nsAReadableString& aName,
const nsAReadableString& aNamespace,
nsISchemaType** aType); nsISchemaType** aType);
nsresult GetSOAPType(const nsAReadableString& aName, nsresult GetSOAPType(const nsAReadableString& aName,
const nsAReadableString& aNamespace, const nsAReadableString& aNamespace,

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

@ -43,7 +43,8 @@ class nsSchema : public nsISchema
{ {
public: public:
nsSchema(nsISchemaCollection* aCollection, nsSchema(nsISchemaCollection* aCollection,
const nsAReadableString& aTargetNamespace); const nsAReadableString& aTargetNamespace,
const nsAReadableString& aSchemaNamespace);
virtual ~nsSchema(); virtual ~nsSchema();
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
@ -61,6 +62,7 @@ public:
protected: protected:
nsString mTargetNamespace; nsString mTargetNamespace;
nsString mSchemaNamespace;
nsSupportsArray mTypes; nsSupportsArray mTypes;
nsSupportsHashtable mTypesHash; nsSupportsHashtable mTypesHash;
nsSupportsArray mAttributes; nsSupportsArray mAttributes;
@ -98,7 +100,8 @@ protected:
class nsSchemaBuiltinType : public nsISchemaBuiltinType class nsSchemaBuiltinType : public nsISchemaBuiltinType
{ {
public: public:
nsSchemaBuiltinType(PRUint16 aBuiltinType); nsSchemaBuiltinType(PRUint16 aBuiltinType,
const nsAReadableString& aName);
virtual ~nsSchemaBuiltinType(); virtual ~nsSchemaBuiltinType();
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
@ -109,6 +112,7 @@ public:
protected: protected:
PRUint16 mBuiltinType; PRUint16 mBuiltinType;
nsString mNamespace;
}; };
class nsSchemaListType : public nsSchemaComponentBase, class nsSchemaListType : public nsSchemaComponentBase,

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

@ -28,8 +28,9 @@
// nsSchemaBuiltinType implementation // nsSchemaBuiltinType implementation
// //
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
nsSchemaBuiltinType::nsSchemaBuiltinType(PRUint16 aBuiltinType) nsSchemaBuiltinType::nsSchemaBuiltinType(PRUint16 aBuiltinType,
: mBuiltinType(aBuiltinType) const nsAReadableString& aNamespace)
: mBuiltinType(aBuiltinType), mNamespace(aNamespace)
{ {
NS_INIT_ISUPPORTS(); NS_INIT_ISUPPORTS();
} }
@ -48,7 +49,7 @@ NS_IMPL_ISUPPORTS4_CI(nsSchemaBuiltinType,
NS_IMETHODIMP NS_IMETHODIMP
nsSchemaBuiltinType::GetTargetNamespace(nsAWritableString& aTargetNamespace) nsSchemaBuiltinType::GetTargetNamespace(nsAWritableString& aTargetNamespace)
{ {
aTargetNamespace.Assign(NS_LITERAL_STRING(NS_SCHEMA_2001_NAMESPACE)); aTargetNamespace.Assign(mNamespace);
return NS_OK; return NS_OK;
} }