Added nsISchemaCollection interface. Started using DOM3 namespace lookup methods. This is not (as yet) part of the build.

This commit is contained in:
vidur%netscape.com 2001-09-14 20:56:06 +00:00
parent 8c561c37b0
commit 272eb7f450
17 changed files with 655 additions and 756 deletions

View File

@ -27,7 +27,6 @@
#include "nsAWritableString.h" #include "nsAWritableString.h"
%} %}
interface nsISchemaComponent;
interface nsISchema; interface nsISchema;
interface nsISchemaType; interface nsISchemaType;
interface nsISchemaSimpleType; interface nsISchemaSimpleType;
@ -46,6 +45,19 @@ interface nsISchemaAttributeGroup;
interface nsISchemaAnyAttribute; interface nsISchemaAnyAttribute;
interface nsISchemaFacet; interface nsISchemaFacet;
/**
* The collection of loaded schemas. If a schema references other
* schemas (generally through an import), these will be included
* in the corresponding collection.
*/
[scriptable, uuid(427c5511-941b-48c0-9abc-8ec9ea5d964b)]
interface nsISchemaCollection : nsISupports {
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);
};
[scriptable, uuid(3c14a020-6f4e-11d5-9b46-000064657374)] [scriptable, uuid(3c14a020-6f4e-11d5-9b46-000064657374)]
interface nsISchemaComponent : nsISupports { interface nsISchemaComponent : nsISupports {
readonly attribute AString targetNamespace; readonly attribute AString targetNamespace;
@ -74,6 +86,8 @@ interface nsISchema : nsISchemaComponent {
readonly attribute PRUint32 modelGroupCount; readonly attribute PRUint32 modelGroupCount;
nsISchemaModelGroup getModelGroupByIndex(in PRUint32 index); nsISchemaModelGroup getModelGroupByIndex(in PRUint32 index);
nsISchemaModelGroup getModelGroupByName(in AString name); nsISchemaModelGroup getModelGroupByName(in AString name);
readonly attribute nsISchemaCollection collection;
}; };
[scriptable, uuid(3c14a022-6f4e-11d5-9b46-000064657374)] [scriptable, uuid(3c14a022-6f4e-11d5-9b46-000064657374)]
@ -222,6 +236,10 @@ interface nsISchemaModelGroup : nsISchemaParticle {
readonly attribute PRUint32 particleCount; readonly attribute PRUint32 particleCount;
nsISchemaParticle getParticle(in PRUint32 index); nsISchemaParticle getParticle(in PRUint32 index);
// Get named element definition for a named element that is
// part of this model group or part of a nested model group.
nsISchemaElement getElementByName(in AString name);
}; };
[scriptable, uuid(3c14a02b-6f4e-11d5-9b46-000064657374)] [scriptable, uuid(3c14a02b-6f4e-11d5-9b46-000064657374)]

View File

@ -24,6 +24,7 @@
#include "nsISupports.idl" #include "nsISupports.idl"
interface nsISchema; interface nsISchema;
interface nsISchemaType;
interface nsIDOMElement; interface nsIDOMElement;
interface nsISchemaLoadListener; interface nsISchemaLoadListener;
@ -49,4 +50,14 @@ interface nsISchemaLoadListener : nsISupports {
{0x9b, 0x49, 0x00, 0x10, 0x4b, 0xdf, 0x53, 0x39}} {0x9b, 0x49, 0x00, 0x10, 0x4b, 0xdf, 0x53, 0x39}}
#define NS_SCHEMALOADER_CONTRACTID "@mozilla.org/xmlextras/schemas/schemaloader;1" #define NS_SCHEMALOADER_CONTRACTID "@mozilla.org/xmlextras/schemas/schemaloader;1"
#define NS_ERROR_SCHEMA_NOT_SCHEMA_ELEMENT NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GENERAL, 1)
#define NS_ERROR_SCHEMA_UNKNOWN_TARGET_NAMESPACE NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GENERAL, 2)
#define NS_ERROR_SCHEMA_UNKNOWN_TYPE NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GENERAL, 3)
#define NS_ERROR_SCHEMA_UNKNOWN_PREFIX NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GENERAL, 4)
#define NS_ERROR_SCHEMA_INVALID_STRUCTURE NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GENERAL, 5)
#define NS_ERROR_SCHEMA_INVALID_TYPE_USAGE NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GENERAL, 6)
#define NS_ERROR_SCHEMA_MISSING_TYPE NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GENERAL, 7)
#define NS_ERROR_SCHEMA_FACET_VALUE_ERROR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GENERAL, 8)
#define NS_ERROR_SCHEMA_LOADING_ERROR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GENERAL, 9)
%} %}

View File

@ -45,3 +45,6 @@ CPPSRCS = \
FORCE_STATIC_LIB = 1 FORCE_STATIC_LIB = 1
include $(topsrcdir)/config/rules.mk include $(topsrcdir)/config/rules.mk
INCLUDES += \
$(NULL)

View File

@ -28,10 +28,12 @@
// nsSchema implementation // nsSchema implementation
// //
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
nsSchema::nsSchema(const nsAReadableString& aTargetNamespace) nsSchema::nsSchema(nsISchemaCollection* aCollection,
const nsAReadableString& aTargetNamespace)
: mTargetNamespace(aTargetNamespace) : mTargetNamespace(aTargetNamespace)
{ {
NS_INIT_ISUPPORTS(); NS_INIT_ISUPPORTS();
mCollection = aCollection; // Weak reference
} }
nsSchema::~nsSchema() nsSchema::~nsSchema()
@ -372,6 +374,18 @@ nsSchema::GetModelGroupByName(const nsAReadableString& name, nsISchemaModelGroup
return NS_OK; return NS_OK;
} }
/* readonly attribute nsISchemaCollection collection; */
NS_IMETHODIMP
nsSchema::GetCollection(nsISchemaCollection** _retval)
{
NS_ENSURE_ARG_POINTER(_retval);
*_retval = mCollection;
NS_IF_ADDREF(*_retval);
return NS_OK;
}
NS_IMETHODIMP NS_IMETHODIMP
nsSchema::AddType(nsISchemaType* aType) nsSchema::AddType(nsISchemaType* aType)
{ {
@ -447,6 +461,12 @@ nsSchema::AddModelGroup(nsISchemaModelGroup* aModelGroup)
return NS_OK; return NS_OK;
} }
void
nsSchema::DropCollectionReference()
{
mCollection = nsnull;
}
nsresult nsresult
nsSchema::ResolveTypePlaceholder(nsISchemaType* aPlaceholder, nsSchema::ResolveTypePlaceholder(nsISchemaType* aPlaceholder,
nsISchemaType** aType) nsISchemaType** aType)

File diff suppressed because it is too large Load Diff

View File

@ -26,10 +26,12 @@
#include "nsISchemaLoader.h" #include "nsISchemaLoader.h"
#include "nsSchemaPrivate.h" #include "nsSchemaPrivate.h"
#include "nsDOMUtils.h"
// DOM includes // DOM includes
#include "nsIDOMElement.h" #include "nsIDOMElement.h"
#include "nsIDOMNodeList.h" #include "nsIDOMNodeList.h"
#include "nsIDOMNode.h"
// XPCOM Includes // XPCOM Includes
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
@ -42,9 +44,6 @@
// Loading includes // Loading includes
#include "nsIURI.h" #include "nsIURI.h"
// Forward declarations
class nsSchemaLoadingContext;
class nsSchemaAtoms { class nsSchemaAtoms {
public: public:
static void CreateSchemaAtoms(); static void CreateSchemaAtoms();
@ -129,7 +128,8 @@ public:
static nsIAtom* sPattern_atom; static nsIAtom* sPattern_atom;
}; };
class nsSchemaLoader : public nsISchemaLoader class nsSchemaLoader : public nsISchemaLoader,
public nsISchemaCollection
{ {
public: public:
nsSchemaLoader(); nsSchemaLoader();
@ -137,102 +137,86 @@ public:
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
NS_DECL_NSISCHEMALOADER NS_DECL_NSISCHEMALOADER
NS_DECL_NSISCHEMACOLLECTION
protected: protected:
nsresult ProcessElement(nsSchema* aSchema, nsresult ProcessElement(nsSchema* aSchema,
nsSchemaLoadingContext* aContext,
nsIDOMElement* aElement, nsIDOMElement* aElement,
nsISchemaElement** aSchemaElement); nsISchemaElement** aSchemaElement);
nsresult ProcessComplexType(nsSchema* aSchema, nsresult ProcessComplexType(nsSchema* aSchema,
nsSchemaLoadingContext* aContext,
nsIDOMElement* aElement, nsIDOMElement* aElement,
nsISchemaComplexType** aComplexType); nsISchemaComplexType** aComplexType);
nsresult ProcessComplexTypeBody(nsSchema* aSchema, nsresult ProcessComplexTypeBody(nsSchema* aSchema,
nsSchemaLoadingContext* aContext,
nsIDOMElement* aElement, nsIDOMElement* aElement,
nsSchemaComplexType* aComplexType, nsSchemaComplexType* aComplexType,
nsSchemaModelGroup* aSequence, nsSchemaModelGroup* aSequence,
PRUint16* aContentModel); PRUint16* aContentModel);
nsresult ProcessSimpleContent(nsSchema* aSchema, nsresult ProcessSimpleContent(nsSchema* aSchema,
nsSchemaLoadingContext* aContext,
nsIDOMElement* aElement, nsIDOMElement* aElement,
nsSchemaComplexType* aComplexType, nsSchemaComplexType* aComplexType,
PRUint16* aDerivation, PRUint16* aDerivation,
nsISchemaType** aBaseType); nsISchemaType** aBaseType);
nsresult ProcessSimpleContentRestriction(nsSchema* aSchema, nsresult ProcessSimpleContentRestriction(nsSchema* aSchema,
nsSchemaLoadingContext* aContext,
nsIDOMElement* aElement, nsIDOMElement* aElement,
nsSchemaComplexType* aComplexType, nsSchemaComplexType* aComplexType,
nsISchemaType* aBaseType, nsISchemaType* aBaseType,
nsISchemaSimpleType** aSimpleBaseType); nsISchemaSimpleType** aSimpleBaseType);
nsresult ProcessSimpleContentExtension(nsSchema* aSchema, nsresult ProcessSimpleContentExtension(nsSchema* aSchema,
nsSchemaLoadingContext* aContext,
nsIDOMElement* aElement, nsIDOMElement* aElement,
nsSchemaComplexType* aComplexType, nsSchemaComplexType* aComplexType,
nsISchemaType* aBaseType, nsISchemaType* aBaseType,
nsISchemaSimpleType** aSimpleBaseType); nsISchemaSimpleType** aSimpleBaseType);
nsresult ProcessComplexContent(nsSchema* aSchema, nsresult ProcessComplexContent(nsSchema* aSchema,
nsSchemaLoadingContext* aContext,
nsIDOMElement* aElement, nsIDOMElement* aElement,
nsSchemaComplexType* aComplexType, nsSchemaComplexType* aComplexType,
PRUint16* aContentModel, PRUint16* aContentModel,
PRUint16* aDerivation, PRUint16* aDerivation,
nsISchemaType** aBaseType); nsISchemaType** aBaseType);
nsresult ProcessSimpleType(nsSchema* aSchema, nsresult ProcessSimpleType(nsSchema* aSchema,
nsSchemaLoadingContext* aContext,
nsIDOMElement* aElement, nsIDOMElement* aElement,
nsISchemaSimpleType** aSimpleType); nsISchemaSimpleType** aSimpleType);
nsresult ProcessSimpleTypeRestriction(nsSchema* aSchema, nsresult ProcessSimpleTypeRestriction(nsSchema* aSchema,
nsSchemaLoadingContext* aContext,
nsIDOMElement* aElement, nsIDOMElement* aElement,
const nsAReadableString& aName, const nsAReadableString& aName,
nsISchemaSimpleType** aSimpleType); nsISchemaSimpleType** aSimpleType);
nsresult ProcessSimpleTypeList(nsSchema* aSchema, nsresult ProcessSimpleTypeList(nsSchema* aSchema,
nsSchemaLoadingContext* aContext,
nsIDOMElement* aElement, nsIDOMElement* aElement,
const nsAReadableString& aName, const nsAReadableString& aName,
nsISchemaSimpleType** aSimpleType); nsISchemaSimpleType** aSimpleType);
nsresult ProcessSimpleTypeUnion(nsSchema* aSchema, nsresult ProcessSimpleTypeUnion(nsSchema* aSchema,
nsSchemaLoadingContext* aContext,
nsIDOMElement* aElement, nsIDOMElement* aElement,
const nsAReadableString& aName, const nsAReadableString& aName,
nsISchemaSimpleType** aSimpleType); nsISchemaSimpleType** aSimpleType);
nsresult ProcessAttribute(nsSchema* aSchema, nsresult ProcessAttribute(nsSchema* aSchema,
nsSchemaLoadingContext* aContext,
nsIDOMElement* aElement, nsIDOMElement* aElement,
nsISchemaAttribute** aAttribute); nsISchemaAttribute** aAttribute);
nsresult ProcessAttributeGroup(nsSchema* aSchema, nsresult ProcessAttributeGroup(nsSchema* aSchema,
nsSchemaLoadingContext* aContext,
nsIDOMElement* aElement, nsIDOMElement* aElement,
nsISchemaAttributeGroup** aAttributeGroup); nsISchemaAttributeGroup** aAttributeGroup);
nsresult ProcessAttributeComponent(nsSchema* aSchema, nsresult ProcessAttributeComponent(nsSchema* aSchema,
nsSchemaLoadingContext* aContext,
nsIDOMElement* aElement, nsIDOMElement* aElement,
nsIAtom* aTagName, nsIAtom* aTagName,
nsISchemaAttributeComponent** aAttribute); nsISchemaAttributeComponent** aAttribute);
nsresult ProcessModelGroup(nsSchema* aSchema, nsresult ProcessModelGroup(nsSchema* aSchema,
nsSchemaLoadingContext* aContext,
nsIDOMElement* aElement, nsIDOMElement* aElement,
nsIAtom* aTagName, nsIAtom* aTagName,
nsSchemaModelGroup* aParentSequence, nsSchemaModelGroup* aParentSequence,
nsISchemaModelGroup** aModelGroup); nsISchemaModelGroup** aModelGroup);
nsresult ProcessParticle(nsSchema* aSchema, nsresult ProcessParticle(nsSchema* aSchema,
nsSchemaLoadingContext* aContext,
nsIDOMElement* aElement, nsIDOMElement* aElement,
nsIAtom* aTagName, nsIAtom* aTagName,
nsISchemaParticle** aModelGroup); nsISchemaParticle** aModelGroup);
nsresult ProcessFacet(nsSchema* aSchema, nsresult ProcessFacet(nsSchema* aSchema,
nsSchemaLoadingContext* aContext,
nsIDOMElement* aElement, nsIDOMElement* aElement,
nsIAtom* aTagName, nsIAtom* aTagName,
nsISchemaFacet** aFacet); nsISchemaFacet** aFacet);
nsresult GetBuiltinType(const nsAReadableString& aName,
nsISchemaType** aType);
nsresult GetNewOrUsedType(nsSchema* aSchema, nsresult GetNewOrUsedType(nsSchema* aSchema,
nsSchemaLoadingContext* aContext, nsIDOMElement* aContext,
const nsAReadableString& aTypeName, const nsAReadableString& aTypeName,
nsISchemaType** aType); nsISchemaType** aType);
nsresult GetBuiltinType(const nsAReadableString& aName,
nsISchemaType** aType);
void GetUse(nsIDOMElement* aElement, void GetUse(nsIDOMElement* aElement,
PRUint16* aUse); PRUint16* aUse);
@ -247,20 +231,8 @@ protected:
protected: protected:
nsSupportsHashtable mBuiltinTypesHash; nsSupportsHashtable mBuiltinTypesHash;
}; nsSupportsHashtable mSOAPTypeHash;
nsSupportsHashtable mSchemas;
class nsSchemaLoadingContext {
public:
nsSchemaLoadingContext();
~nsSchemaLoadingContext();
nsresult PushNamespaceDecls(nsIDOMElement* aElement);
nsresult PopNamespaceDecls(nsIDOMElement* aElement);
PRBool GetNamespaceURIForPrefix(const nsAReadableString& aPrefix,
nsAWritableString& aURI);
protected:
nsVoidArray mNamespaceStack;
}; };
#endif // __nsSchemaLoader_h__ #endif // __nsSchemaLoader_h__

View File

@ -206,6 +206,44 @@ nsSchemaModelGroup::GetParticle(PRUint32 index, nsISchemaParticle **_retval)
(void**)_retval); (void**)_retval);
} }
/* nsISchemaElement getElementByName(in AString name); */
NS_IMETHODIMP
nsSchemaModelGroup::GetElementByName(const nsAReadableString& aName,
nsISchemaElement** _retval)
{
NS_ENSURE_ARG_POINTER(_retval);
PRUint32 i, count;
mParticles.Count(&count);
for (i = 0; i < count; i++) {
nsCOMPtr<nsISchemaParticle> particle;
GetParticle(i, getter_AddRefs(particle));
nsCOMPtr<nsISchemaElement> element(do_QueryInterface(particle));
if (element) {
nsAutoString name;
element->GetName(name);
if (name.Equals(aName)) {
*_retval = element;
NS_ADDREF(*_retval);
return NS_OK;
}
}
else {
nsCOMPtr<nsISchemaModelGroup> group(do_QueryInterface(particle));
if (group) {
nsresult rv = group->GetElementByName(aName, _retval);
if (NS_SUCCEEDED(rv)) {
return NS_OK;
}
}
}
}
return NS_ERROR_FAILURE; // No element of that name found
}
NS_IMETHODIMP NS_IMETHODIMP
nsSchemaModelGroup::SetCompositor(PRUint16 aCompositor) nsSchemaModelGroup::SetCompositor(PRUint16 aCompositor)
{ {
@ -342,6 +380,19 @@ nsSchemaModelGroupRef::GetParticle(PRUint32 index, nsISchemaParticle **_retval)
return mModelGroup->GetParticle(index, _retval); return mModelGroup->GetParticle(index, _retval);
} }
NS_IMETHODIMP
nsSchemaModelGroupRef::GetElementByName(const nsAReadableString& aName,
nsISchemaElement** _retval)
{
NS_ENSURE_ARG_POINTER(_retval);
if (!mModelGroup) {
return NS_ERROR_NOT_INITIALIZED;
}
return mModelGroup->GetElementByName(aName, _retval);
}
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// //
// nsSchemaAnyParticle implementation // nsSchemaAnyParticle implementation

View File

@ -37,7 +37,8 @@
class nsSchema : public nsISchema class nsSchema : public nsISchema
{ {
public: public:
nsSchema(const nsAReadableString& aTargetNamespace); nsSchema(nsISchemaCollection* aCollection,
const nsAReadableString& aTargetNamespace);
virtual ~nsSchema(); virtual ~nsSchema();
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
@ -49,6 +50,7 @@ public:
NS_IMETHOD AddElement(nsISchemaElement* aElement); NS_IMETHOD AddElement(nsISchemaElement* aElement);
NS_IMETHOD AddAttributeGroup(nsISchemaAttributeGroup* aAttributeGroup); NS_IMETHOD AddAttributeGroup(nsISchemaAttributeGroup* aAttributeGroup);
NS_IMETHOD AddModelGroup(nsISchemaModelGroup* aModelGroup); NS_IMETHOD AddModelGroup(nsISchemaModelGroup* aModelGroup);
void DropCollectionReference();
nsresult ResolveTypePlaceholder(nsISchemaType* aPlaceholder, nsresult ResolveTypePlaceholder(nsISchemaType* aPlaceholder,
nsISchemaType** aType); nsISchemaType** aType);
@ -64,6 +66,7 @@ protected:
nsSupportsHashtable mAttributeGroupsHash; nsSupportsHashtable mAttributeGroupsHash;
nsSupportsArray mModelGroups; nsSupportsArray mModelGroups;
nsSupportsHashtable mModelGroupsHash; nsSupportsHashtable mModelGroupsHash;
nsISchemaCollection* mCollection; // [WEAK] it owns me
}; };
class nsSchemaComponentBase { class nsSchemaComponentBase {

View File

@ -26,5 +26,6 @@ XPIDLSRCS = .\nsISchema.idl \
$(NULL) $(NULL)
MODULE=xmlextras MODULE=xmlextras
XPIDL_MODULE=xmlschema
include <$(DEPTH)\config\rules.mak> include <$(DEPTH)\config\rules.mak>

View File

@ -27,7 +27,6 @@
#include "nsAWritableString.h" #include "nsAWritableString.h"
%} %}
interface nsISchemaComponent;
interface nsISchema; interface nsISchema;
interface nsISchemaType; interface nsISchemaType;
interface nsISchemaSimpleType; interface nsISchemaSimpleType;
@ -46,6 +45,19 @@ interface nsISchemaAttributeGroup;
interface nsISchemaAnyAttribute; interface nsISchemaAnyAttribute;
interface nsISchemaFacet; interface nsISchemaFacet;
/**
* The collection of loaded schemas. If a schema references other
* schemas (generally through an import), these will be included
* in the corresponding collection.
*/
[scriptable, uuid(427c5511-941b-48c0-9abc-8ec9ea5d964b)]
interface nsISchemaCollection : nsISupports {
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);
};
[scriptable, uuid(3c14a020-6f4e-11d5-9b46-000064657374)] [scriptable, uuid(3c14a020-6f4e-11d5-9b46-000064657374)]
interface nsISchemaComponent : nsISupports { interface nsISchemaComponent : nsISupports {
readonly attribute AString targetNamespace; readonly attribute AString targetNamespace;
@ -74,6 +86,8 @@ interface nsISchema : nsISchemaComponent {
readonly attribute PRUint32 modelGroupCount; readonly attribute PRUint32 modelGroupCount;
nsISchemaModelGroup getModelGroupByIndex(in PRUint32 index); nsISchemaModelGroup getModelGroupByIndex(in PRUint32 index);
nsISchemaModelGroup getModelGroupByName(in AString name); nsISchemaModelGroup getModelGroupByName(in AString name);
readonly attribute nsISchemaCollection collection;
}; };
[scriptable, uuid(3c14a022-6f4e-11d5-9b46-000064657374)] [scriptable, uuid(3c14a022-6f4e-11d5-9b46-000064657374)]
@ -222,6 +236,10 @@ interface nsISchemaModelGroup : nsISchemaParticle {
readonly attribute PRUint32 particleCount; readonly attribute PRUint32 particleCount;
nsISchemaParticle getParticle(in PRUint32 index); nsISchemaParticle getParticle(in PRUint32 index);
// Get named element definition for a named element that is
// part of this model group or part of a nested model group.
nsISchemaElement getElementByName(in AString name);
}; };
[scriptable, uuid(3c14a02b-6f4e-11d5-9b46-000064657374)] [scriptable, uuid(3c14a02b-6f4e-11d5-9b46-000064657374)]

View File

@ -24,6 +24,7 @@
#include "nsISupports.idl" #include "nsISupports.idl"
interface nsISchema; interface nsISchema;
interface nsISchemaType;
interface nsIDOMElement; interface nsIDOMElement;
interface nsISchemaLoadListener; interface nsISchemaLoadListener;
@ -49,4 +50,14 @@ interface nsISchemaLoadListener : nsISupports {
{0x9b, 0x49, 0x00, 0x10, 0x4b, 0xdf, 0x53, 0x39}} {0x9b, 0x49, 0x00, 0x10, 0x4b, 0xdf, 0x53, 0x39}}
#define NS_SCHEMALOADER_CONTRACTID "@mozilla.org/xmlextras/schemas/schemaloader;1" #define NS_SCHEMALOADER_CONTRACTID "@mozilla.org/xmlextras/schemas/schemaloader;1"
#define NS_ERROR_SCHEMA_NOT_SCHEMA_ELEMENT NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GENERAL, 1)
#define NS_ERROR_SCHEMA_UNKNOWN_TARGET_NAMESPACE NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GENERAL, 2)
#define NS_ERROR_SCHEMA_UNKNOWN_TYPE NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GENERAL, 3)
#define NS_ERROR_SCHEMA_UNKNOWN_PREFIX NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GENERAL, 4)
#define NS_ERROR_SCHEMA_INVALID_STRUCTURE NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GENERAL, 5)
#define NS_ERROR_SCHEMA_INVALID_TYPE_USAGE NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GENERAL, 6)
#define NS_ERROR_SCHEMA_MISSING_TYPE NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GENERAL, 7)
#define NS_ERROR_SCHEMA_FACET_VALUE_ERROR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GENERAL, 8)
#define NS_ERROR_SCHEMA_LOADING_ERROR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GENERAL, 9)
%} %}

View File

@ -45,3 +45,6 @@ CPPSRCS = \
FORCE_STATIC_LIB = 1 FORCE_STATIC_LIB = 1
include $(topsrcdir)/config/rules.mk include $(topsrcdir)/config/rules.mk
INCLUDES += \
$(NULL)

View File

@ -28,10 +28,12 @@
// nsSchema implementation // nsSchema implementation
// //
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
nsSchema::nsSchema(const nsAReadableString& aTargetNamespace) nsSchema::nsSchema(nsISchemaCollection* aCollection,
const nsAReadableString& aTargetNamespace)
: mTargetNamespace(aTargetNamespace) : mTargetNamespace(aTargetNamespace)
{ {
NS_INIT_ISUPPORTS(); NS_INIT_ISUPPORTS();
mCollection = aCollection; // Weak reference
} }
nsSchema::~nsSchema() nsSchema::~nsSchema()
@ -372,6 +374,18 @@ nsSchema::GetModelGroupByName(const nsAReadableString& name, nsISchemaModelGroup
return NS_OK; return NS_OK;
} }
/* readonly attribute nsISchemaCollection collection; */
NS_IMETHODIMP
nsSchema::GetCollection(nsISchemaCollection** _retval)
{
NS_ENSURE_ARG_POINTER(_retval);
*_retval = mCollection;
NS_IF_ADDREF(*_retval);
return NS_OK;
}
NS_IMETHODIMP NS_IMETHODIMP
nsSchema::AddType(nsISchemaType* aType) nsSchema::AddType(nsISchemaType* aType)
{ {
@ -447,6 +461,12 @@ nsSchema::AddModelGroup(nsISchemaModelGroup* aModelGroup)
return NS_OK; return NS_OK;
} }
void
nsSchema::DropCollectionReference()
{
mCollection = nsnull;
}
nsresult nsresult
nsSchema::ResolveTypePlaceholder(nsISchemaType* aPlaceholder, nsSchema::ResolveTypePlaceholder(nsISchemaType* aPlaceholder,
nsISchemaType** aType) nsISchemaType** aType)

File diff suppressed because it is too large Load Diff

View File

@ -26,10 +26,12 @@
#include "nsISchemaLoader.h" #include "nsISchemaLoader.h"
#include "nsSchemaPrivate.h" #include "nsSchemaPrivate.h"
#include "nsDOMUtils.h"
// DOM includes // DOM includes
#include "nsIDOMElement.h" #include "nsIDOMElement.h"
#include "nsIDOMNodeList.h" #include "nsIDOMNodeList.h"
#include "nsIDOMNode.h"
// XPCOM Includes // XPCOM Includes
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
@ -42,9 +44,6 @@
// Loading includes // Loading includes
#include "nsIURI.h" #include "nsIURI.h"
// Forward declarations
class nsSchemaLoadingContext;
class nsSchemaAtoms { class nsSchemaAtoms {
public: public:
static void CreateSchemaAtoms(); static void CreateSchemaAtoms();
@ -129,7 +128,8 @@ public:
static nsIAtom* sPattern_atom; static nsIAtom* sPattern_atom;
}; };
class nsSchemaLoader : public nsISchemaLoader class nsSchemaLoader : public nsISchemaLoader,
public nsISchemaCollection
{ {
public: public:
nsSchemaLoader(); nsSchemaLoader();
@ -137,102 +137,86 @@ public:
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
NS_DECL_NSISCHEMALOADER NS_DECL_NSISCHEMALOADER
NS_DECL_NSISCHEMACOLLECTION
protected: protected:
nsresult ProcessElement(nsSchema* aSchema, nsresult ProcessElement(nsSchema* aSchema,
nsSchemaLoadingContext* aContext,
nsIDOMElement* aElement, nsIDOMElement* aElement,
nsISchemaElement** aSchemaElement); nsISchemaElement** aSchemaElement);
nsresult ProcessComplexType(nsSchema* aSchema, nsresult ProcessComplexType(nsSchema* aSchema,
nsSchemaLoadingContext* aContext,
nsIDOMElement* aElement, nsIDOMElement* aElement,
nsISchemaComplexType** aComplexType); nsISchemaComplexType** aComplexType);
nsresult ProcessComplexTypeBody(nsSchema* aSchema, nsresult ProcessComplexTypeBody(nsSchema* aSchema,
nsSchemaLoadingContext* aContext,
nsIDOMElement* aElement, nsIDOMElement* aElement,
nsSchemaComplexType* aComplexType, nsSchemaComplexType* aComplexType,
nsSchemaModelGroup* aSequence, nsSchemaModelGroup* aSequence,
PRUint16* aContentModel); PRUint16* aContentModel);
nsresult ProcessSimpleContent(nsSchema* aSchema, nsresult ProcessSimpleContent(nsSchema* aSchema,
nsSchemaLoadingContext* aContext,
nsIDOMElement* aElement, nsIDOMElement* aElement,
nsSchemaComplexType* aComplexType, nsSchemaComplexType* aComplexType,
PRUint16* aDerivation, PRUint16* aDerivation,
nsISchemaType** aBaseType); nsISchemaType** aBaseType);
nsresult ProcessSimpleContentRestriction(nsSchema* aSchema, nsresult ProcessSimpleContentRestriction(nsSchema* aSchema,
nsSchemaLoadingContext* aContext,
nsIDOMElement* aElement, nsIDOMElement* aElement,
nsSchemaComplexType* aComplexType, nsSchemaComplexType* aComplexType,
nsISchemaType* aBaseType, nsISchemaType* aBaseType,
nsISchemaSimpleType** aSimpleBaseType); nsISchemaSimpleType** aSimpleBaseType);
nsresult ProcessSimpleContentExtension(nsSchema* aSchema, nsresult ProcessSimpleContentExtension(nsSchema* aSchema,
nsSchemaLoadingContext* aContext,
nsIDOMElement* aElement, nsIDOMElement* aElement,
nsSchemaComplexType* aComplexType, nsSchemaComplexType* aComplexType,
nsISchemaType* aBaseType, nsISchemaType* aBaseType,
nsISchemaSimpleType** aSimpleBaseType); nsISchemaSimpleType** aSimpleBaseType);
nsresult ProcessComplexContent(nsSchema* aSchema, nsresult ProcessComplexContent(nsSchema* aSchema,
nsSchemaLoadingContext* aContext,
nsIDOMElement* aElement, nsIDOMElement* aElement,
nsSchemaComplexType* aComplexType, nsSchemaComplexType* aComplexType,
PRUint16* aContentModel, PRUint16* aContentModel,
PRUint16* aDerivation, PRUint16* aDerivation,
nsISchemaType** aBaseType); nsISchemaType** aBaseType);
nsresult ProcessSimpleType(nsSchema* aSchema, nsresult ProcessSimpleType(nsSchema* aSchema,
nsSchemaLoadingContext* aContext,
nsIDOMElement* aElement, nsIDOMElement* aElement,
nsISchemaSimpleType** aSimpleType); nsISchemaSimpleType** aSimpleType);
nsresult ProcessSimpleTypeRestriction(nsSchema* aSchema, nsresult ProcessSimpleTypeRestriction(nsSchema* aSchema,
nsSchemaLoadingContext* aContext,
nsIDOMElement* aElement, nsIDOMElement* aElement,
const nsAReadableString& aName, const nsAReadableString& aName,
nsISchemaSimpleType** aSimpleType); nsISchemaSimpleType** aSimpleType);
nsresult ProcessSimpleTypeList(nsSchema* aSchema, nsresult ProcessSimpleTypeList(nsSchema* aSchema,
nsSchemaLoadingContext* aContext,
nsIDOMElement* aElement, nsIDOMElement* aElement,
const nsAReadableString& aName, const nsAReadableString& aName,
nsISchemaSimpleType** aSimpleType); nsISchemaSimpleType** aSimpleType);
nsresult ProcessSimpleTypeUnion(nsSchema* aSchema, nsresult ProcessSimpleTypeUnion(nsSchema* aSchema,
nsSchemaLoadingContext* aContext,
nsIDOMElement* aElement, nsIDOMElement* aElement,
const nsAReadableString& aName, const nsAReadableString& aName,
nsISchemaSimpleType** aSimpleType); nsISchemaSimpleType** aSimpleType);
nsresult ProcessAttribute(nsSchema* aSchema, nsresult ProcessAttribute(nsSchema* aSchema,
nsSchemaLoadingContext* aContext,
nsIDOMElement* aElement, nsIDOMElement* aElement,
nsISchemaAttribute** aAttribute); nsISchemaAttribute** aAttribute);
nsresult ProcessAttributeGroup(nsSchema* aSchema, nsresult ProcessAttributeGroup(nsSchema* aSchema,
nsSchemaLoadingContext* aContext,
nsIDOMElement* aElement, nsIDOMElement* aElement,
nsISchemaAttributeGroup** aAttributeGroup); nsISchemaAttributeGroup** aAttributeGroup);
nsresult ProcessAttributeComponent(nsSchema* aSchema, nsresult ProcessAttributeComponent(nsSchema* aSchema,
nsSchemaLoadingContext* aContext,
nsIDOMElement* aElement, nsIDOMElement* aElement,
nsIAtom* aTagName, nsIAtom* aTagName,
nsISchemaAttributeComponent** aAttribute); nsISchemaAttributeComponent** aAttribute);
nsresult ProcessModelGroup(nsSchema* aSchema, nsresult ProcessModelGroup(nsSchema* aSchema,
nsSchemaLoadingContext* aContext,
nsIDOMElement* aElement, nsIDOMElement* aElement,
nsIAtom* aTagName, nsIAtom* aTagName,
nsSchemaModelGroup* aParentSequence, nsSchemaModelGroup* aParentSequence,
nsISchemaModelGroup** aModelGroup); nsISchemaModelGroup** aModelGroup);
nsresult ProcessParticle(nsSchema* aSchema, nsresult ProcessParticle(nsSchema* aSchema,
nsSchemaLoadingContext* aContext,
nsIDOMElement* aElement, nsIDOMElement* aElement,
nsIAtom* aTagName, nsIAtom* aTagName,
nsISchemaParticle** aModelGroup); nsISchemaParticle** aModelGroup);
nsresult ProcessFacet(nsSchema* aSchema, nsresult ProcessFacet(nsSchema* aSchema,
nsSchemaLoadingContext* aContext,
nsIDOMElement* aElement, nsIDOMElement* aElement,
nsIAtom* aTagName, nsIAtom* aTagName,
nsISchemaFacet** aFacet); nsISchemaFacet** aFacet);
nsresult GetBuiltinType(const nsAReadableString& aName,
nsISchemaType** aType);
nsresult GetNewOrUsedType(nsSchema* aSchema, nsresult GetNewOrUsedType(nsSchema* aSchema,
nsSchemaLoadingContext* aContext, nsIDOMElement* aContext,
const nsAReadableString& aTypeName, const nsAReadableString& aTypeName,
nsISchemaType** aType); nsISchemaType** aType);
nsresult GetBuiltinType(const nsAReadableString& aName,
nsISchemaType** aType);
void GetUse(nsIDOMElement* aElement, void GetUse(nsIDOMElement* aElement,
PRUint16* aUse); PRUint16* aUse);
@ -247,20 +231,8 @@ protected:
protected: protected:
nsSupportsHashtable mBuiltinTypesHash; nsSupportsHashtable mBuiltinTypesHash;
}; nsSupportsHashtable mSOAPTypeHash;
nsSupportsHashtable mSchemas;
class nsSchemaLoadingContext {
public:
nsSchemaLoadingContext();
~nsSchemaLoadingContext();
nsresult PushNamespaceDecls(nsIDOMElement* aElement);
nsresult PopNamespaceDecls(nsIDOMElement* aElement);
PRBool GetNamespaceURIForPrefix(const nsAReadableString& aPrefix,
nsAWritableString& aURI);
protected:
nsVoidArray mNamespaceStack;
}; };
#endif // __nsSchemaLoader_h__ #endif // __nsSchemaLoader_h__

View File

@ -206,6 +206,44 @@ nsSchemaModelGroup::GetParticle(PRUint32 index, nsISchemaParticle **_retval)
(void**)_retval); (void**)_retval);
} }
/* nsISchemaElement getElementByName(in AString name); */
NS_IMETHODIMP
nsSchemaModelGroup::GetElementByName(const nsAReadableString& aName,
nsISchemaElement** _retval)
{
NS_ENSURE_ARG_POINTER(_retval);
PRUint32 i, count;
mParticles.Count(&count);
for (i = 0; i < count; i++) {
nsCOMPtr<nsISchemaParticle> particle;
GetParticle(i, getter_AddRefs(particle));
nsCOMPtr<nsISchemaElement> element(do_QueryInterface(particle));
if (element) {
nsAutoString name;
element->GetName(name);
if (name.Equals(aName)) {
*_retval = element;
NS_ADDREF(*_retval);
return NS_OK;
}
}
else {
nsCOMPtr<nsISchemaModelGroup> group(do_QueryInterface(particle));
if (group) {
nsresult rv = group->GetElementByName(aName, _retval);
if (NS_SUCCEEDED(rv)) {
return NS_OK;
}
}
}
}
return NS_ERROR_FAILURE; // No element of that name found
}
NS_IMETHODIMP NS_IMETHODIMP
nsSchemaModelGroup::SetCompositor(PRUint16 aCompositor) nsSchemaModelGroup::SetCompositor(PRUint16 aCompositor)
{ {
@ -342,6 +380,19 @@ nsSchemaModelGroupRef::GetParticle(PRUint32 index, nsISchemaParticle **_retval)
return mModelGroup->GetParticle(index, _retval); return mModelGroup->GetParticle(index, _retval);
} }
NS_IMETHODIMP
nsSchemaModelGroupRef::GetElementByName(const nsAReadableString& aName,
nsISchemaElement** _retval)
{
NS_ENSURE_ARG_POINTER(_retval);
if (!mModelGroup) {
return NS_ERROR_NOT_INITIALIZED;
}
return mModelGroup->GetElementByName(aName, _retval);
}
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// //
// nsSchemaAnyParticle implementation // nsSchemaAnyParticle implementation

View File

@ -37,7 +37,8 @@
class nsSchema : public nsISchema class nsSchema : public nsISchema
{ {
public: public:
nsSchema(const nsAReadableString& aTargetNamespace); nsSchema(nsISchemaCollection* aCollection,
const nsAReadableString& aTargetNamespace);
virtual ~nsSchema(); virtual ~nsSchema();
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
@ -49,6 +50,7 @@ public:
NS_IMETHOD AddElement(nsISchemaElement* aElement); NS_IMETHOD AddElement(nsISchemaElement* aElement);
NS_IMETHOD AddAttributeGroup(nsISchemaAttributeGroup* aAttributeGroup); NS_IMETHOD AddAttributeGroup(nsISchemaAttributeGroup* aAttributeGroup);
NS_IMETHOD AddModelGroup(nsISchemaModelGroup* aModelGroup); NS_IMETHOD AddModelGroup(nsISchemaModelGroup* aModelGroup);
void DropCollectionReference();
nsresult ResolveTypePlaceholder(nsISchemaType* aPlaceholder, nsresult ResolveTypePlaceholder(nsISchemaType* aPlaceholder,
nsISchemaType** aType); nsISchemaType** aType);
@ -64,6 +66,7 @@ protected:
nsSupportsHashtable mAttributeGroupsHash; nsSupportsHashtable mAttributeGroupsHash;
nsSupportsArray mModelGroups; nsSupportsArray mModelGroups;
nsSupportsHashtable mModelGroupsHash; nsSupportsHashtable mModelGroupsHash;
nsISchemaCollection* mCollection; // [WEAK] it owns me
}; };
class nsSchemaComponentBase { class nsSchemaComponentBase {