Work in progress on XML Schema representation component

This commit is contained in:
vidur%netscape.com 2001-07-10 17:09:17 +00:00
Родитель e4a06ec97a
Коммит c2b15c1d49
30 изменённых файлов: 7935 добавлений и 0 удалений

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

@ -0,0 +1,303 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla.
*
* The Initial Developer of the Original Code is Netscape
* Communications. Portions created by Netscape Communications are
* Copyright (C) 2001 by Netscape Communications. All
* Rights Reserved.
*
* Contributor(s):
* Vidur Apparao <vidur@netscape.com> (original author)
*/
#include "nsISupports.idl"
%{ C++
#include "nsAWritableString.h"
%}
interface nsISchemaComponent;
interface nsISchema;
interface nsISchemaType;
interface nsISchemaSimpleType;
interface nsISchemaBuiltinType;
interface nsISchemaListType;
interface nsISchemaUnionType;
interface nsISchemaRestrictionType;
interface nsISchemaComplexType;
interface nsISchemaParticle;
interface nsISchemaModelGroup;
interface nsISchemaAnyParticle;
interface nsISchemaElement;
interface nsISchemaAttributeComponent;
interface nsISchemaAttribute;
interface nsISchemaAttributeGroup;
interface nsISchemaAnyAttribute;
interface nsISchemaFacet;
[scriptable, uuid(3c14a020-6f4e-11d5-9b46-000064657374)]
interface nsISchemaComponent : nsISupports {
readonly attribute AString targetNamespace;
void resolve();
void clear();
};
[scriptable, uuid(3c14a021-6f4e-11d5-9b46-000064657374)]
interface nsISchema : nsISchemaComponent {
readonly attribute PRUint32 typeCount;
nsISchemaType getTypeByIndex(in PRUint32 index);
nsISchemaType getTypeByName(in AString name);
readonly attribute PRUint32 attributeCount;
nsISchemaAttribute getAttributeByIndex(in PRUint32 index);
nsISchemaAttribute getAttributeByName(in AString name);
readonly attribute PRUint32 elementCount;
nsISchemaElement getElementByIndex(in PRUint32 index);
nsISchemaElement getElementByName(in AString name);
readonly attribute PRUint32 attributeGroupCount;
nsISchemaAttributeGroup getAttributeGroupByIndex(in PRUint32 index);
nsISchemaAttributeGroup getAttributeGroupByName(in AString name);
readonly attribute PRUint32 modelGroupCount;
nsISchemaModelGroup getModelGroupByIndex(in PRUint32 index);
nsISchemaModelGroup getModelGroupByName(in AString name);
};
[scriptable, uuid(3c14a022-6f4e-11d5-9b46-000064657374)]
interface nsISchemaType : nsISchemaComponent {
const unsigned short SCHEMA_TYPE_SIMPLE = 1;
const unsigned short SCHEMA_TYPE_COMPLEX = 2;
readonly attribute AString name;
readonly attribute unsigned short schemaType;
};
[scriptable, uuid(3c14a023-6f4e-11d5-9b46-000064657374)]
interface nsISchemaSimpleType : nsISchemaType {
const unsigned short SIMPLE_TYPE_BUILTIN = 1;
const unsigned short SIMPLE_TYPE_LIST = 2;
const unsigned short SIMPLE_TYPE_UNION = 3;
const unsigned short SIMPLE_TYPE_RESTRICTION = 4;
readonly attribute unsigned short simpleType;
};
[scriptable, uuid(3c14a024-6f4e-11d5-9b46-000064657374)]
interface nsISchemaBuiltinType : nsISchemaSimpleType {
const unsigned short BUILTIN_TYPE_URTYPE = 1;
const unsigned short BUILTIN_TYPE_STRING = 2;
const unsigned short BUILTIN_TYPE_NORMALIZED_STRING = 3;
const unsigned short BUILTIN_TYPE_TOKEN = 4;
const unsigned short BUILTIN_TYPE_BYTE = 5;
const unsigned short BUILTIN_TYPE_UNSIGNEDBYTE = 6;
const unsigned short BUILTIN_TYPE_BASE64BINARY = 7;
const unsigned short BUILTIN_TYPE_HEXBINARY = 8;
const unsigned short BUILTIN_TYPE_INTEGER = 9;
const unsigned short BUILTIN_TYPE_POSITIVEINTEGER = 10;
const unsigned short BUILTIN_TYPE_NEGATIVEINTEGER = 11;
const unsigned short BUILTIN_TYPE_NONNEGATIVEINTEGER = 12;
const unsigned short BUILTIN_TYPE_NONPOSITIVEINTEGER = 13;
const unsigned short BUILTIN_TYPE_INT = 14;
const unsigned short BUILTIN_TYPE_UNSIGNEDINT = 15;
const unsigned short BUILTIN_TYPE_LONG = 16;
const unsigned short BUILTIN_TYPE_UNSIGNEDLONG = 17;
const unsigned short BUILTIN_TYPE_SHORT = 18;
const unsigned short BUILTIN_TYPE_UNSIGNEDSHORT = 19;
const unsigned short BUILTIN_TYPE_DECIMAL = 20;
const unsigned short BUILTIN_TYPE_FLOAT = 21;
const unsigned short BUILTIN_TYPE_DOUBLE = 22;
const unsigned short BUILTIN_TYPE_BOOLEAN = 23;
const unsigned short BUILTIN_TYPE_TIME = 24;
const unsigned short BUILTIN_TYPE_DATETIME = 25;
const unsigned short BUILTIN_TYPE_DURATION = 26;
const unsigned short BUILTIN_TYPE_DATE = 27;
const unsigned short BUILTIN_TYPE_GMONTH = 28;
const unsigned short BUILTIN_TYPE_GYEAR = 29;
const unsigned short BUILTIN_TYPE_GYEARMONTH = 30;
const unsigned short BUILTIN_TYPE_GDAY = 31;
const unsigned short BUILTIN_TYPE_GMONTHDAY = 32;
const unsigned short BUILTIN_TYPE_NAME = 33;
const unsigned short BUILTIN_TYPE_QNAME = 34;
const unsigned short BUILTIN_TYPE_NCNAME = 35;
const unsigned short BUILTIN_TYPE_ANYURI = 36;
const unsigned short BUILTIN_TYPE_LANGUAGE = 37;
const unsigned short BUILTIN_TYPE_ID = 38;
const unsigned short BUILTIN_TYPE_IDREF = 39;
const unsigned short BUILTIN_TYPE_IDREFS = 40;
const unsigned short BUILTIN_TYPE_ENTITY = 41;
const unsigned short BUILTIN_TYPE_ENTITIES = 42;
const unsigned short BUILTIN_TYPE_NOTATION = 43;
const unsigned short BUILTIN_TYPE_NMTOKEN = 44;
const unsigned short BUILTIN_TYPE_NMTOKENS = 45;
readonly attribute unsigned short builtinType;
};
[scriptable, uuid(3c14a025-6f4e-11d5-9b46-000064657374)]
interface nsISchemaListType : nsISchemaSimpleType {
readonly attribute nsISchemaSimpleType listType;
};
[scriptable, uuid(3c14a026-6f4e-11d5-9b46-000064657374)]
interface nsISchemaUnionType : nsISchemaSimpleType {
readonly attribute PRUint32 unionTypeCount;
nsISchemaSimpleType getUnionType(in PRUint32 index);
};
[scriptable, uuid(3c14a027-6f4e-11d5-9b46-000064657374)]
interface nsISchemaRestrictionType : nsISchemaSimpleType {
readonly attribute nsISchemaSimpleType baseType;
readonly attribute PRUint32 facetCount;
nsISchemaFacet getFacets(in PRUint32 index);
};
[scriptable, uuid(3c14a028-6f4e-11d5-9b46-000064657374)]
interface nsISchemaComplexType : nsISchemaType {
const unsigned short CONTENT_MODEL_EMPTY = 1;
const unsigned short CONTENT_MODEL_SIMPLE = 2;
const unsigned short CONTENT_MODEL_ELEMENT_ONLY = 3;
const unsigned short CONTENT_MODEL_MIXED = 4;
const unsigned short DERIVATION_EXTENSION_SIMPLE = 1;
const unsigned short DERIVATION_EXTENSION_COMPLEX = 2;
const unsigned short DERIVATION_RESTRICTION = 3; // Restriction of a complex type
const unsigned short DERIVATION_SELF_CONTAINED = 4; // Restriction of ur-type
readonly attribute unsigned short contentModel;
readonly attribute unsigned short derivation;
readonly attribute nsISchemaType baseType;
readonly attribute nsISchemaModelGroup modelGroup;
readonly attribute PRUint32 attributeCount;
nsISchemaAttributeComponent getAttributeByIndex(in PRUint32 index);
nsISchemaAttributeComponent getAttributeByName(in AString name);
readonly attribute boolean abstract;
};
[scriptable, uuid(3c14a029-6f4e-11d5-9b46-000064657374)]
interface nsISchemaParticle : nsISchemaComponent {
const unsigned short PARTICLE_TYPE_ELEMENT = 1;
const unsigned short PARTICLE_TYPE_MODEL_GROUP = 2;
const unsigned short PARTICLE_TYPE_ANY = 3;
readonly attribute AString name;
readonly attribute unsigned short particleType;
readonly attribute PRUint32 minOccurs;
readonly attribute PRUint32 maxOccurs;
};
[scriptable, uuid(3c14a02a-6f4e-11d5-9b46-000064657374)]
interface nsISchemaModelGroup : nsISchemaParticle {
const unsigned short COMPOSITOR_ALL = 1;
const unsigned short COMPOSITOR_SEQUENCE = 2;
const unsigned short COMPOSITOR_CHOICE = 3;
readonly attribute unsigned short compositor;
readonly attribute PRUint32 particleCount;
nsISchemaParticle getParticle(in PRUint32 index);
};
[scriptable, uuid(3c14a02b-6f4e-11d5-9b46-000064657374)]
interface nsISchemaAnyParticle : nsISchemaParticle {
const unsigned short PROCESS_STRICT = 1;
const unsigned short PROCESS_SKIP = 2;
const unsigned short PROCESS_LAX = 3;
readonly attribute unsigned short process;
readonly attribute AString namespace;
};
[scriptable, uuid(3c14a02c-6f4e-11d5-9b46-000064657374)]
interface nsISchemaElement : nsISchemaParticle {
readonly attribute nsISchemaType type;
readonly attribute AString defaultValue;
readonly attribute AString fixedValue;
readonly attribute boolean nillable;
readonly attribute boolean abstract;
};
[scriptable, uuid(3c14a02d-6f4e-11d5-9b46-000064657374)]
interface nsISchemaAttributeComponent : nsISchemaComponent {
const unsigned short COMPONENT_TYPE_ATTRIBUTE = 1;
const unsigned short COMPONENT_TYPE_GROUP = 2;
const unsigned short COMPONENT_TYPE_ANY = 3;
readonly attribute AString name;
readonly attribute unsigned short componentType;
};
[scriptable, uuid(3c14a02e-6f4e-11d5-9b46-000064657374)]
interface nsISchemaAttribute : nsISchemaAttributeComponent {
const unsigned short USE_OPTIONAL = 1;
const unsigned short USE_PROHIBITED = 2;
const unsigned short USE_REQUIRED = 3;
readonly attribute nsISchemaSimpleType type;
readonly attribute AString defaultValue;
readonly attribute AString fixedValue;
readonly attribute unsigned short use;
};
[scriptable, uuid(3c14a02f-6f4e-11d5-9b46-000064657374)]
interface nsISchemaAttributeGroup : nsISchemaAttributeComponent {
readonly attribute PRUint32 attributeCount;
nsISchemaAttributeComponent getAttributeByIndex(in PRUint32 index);
nsISchemaAttributeComponent getAttributeByName(in AString name);
};
[scriptable, uuid(3c14a030-6f4e-11d5-9b46-000064657374)]
interface nsISchemaAnyAttribute : nsISchemaAttributeComponent {
const unsigned short PROCESS_STRICT = 1;
const unsigned short PROCESS_SKIP = 2;
const unsigned short PROCESS_LAX = 3;
readonly attribute unsigned short process;
readonly attribute AString namespace;
};
[scriptable, uuid(3c14a031-6f4e-11d5-9b46-000064657374)]
interface nsISchemaFacet : nsISchemaComponent {
const unsigned short FACET_TYPE_LENGTH = 1;
const unsigned short FACET_TYPE_MINLENGTH = 2;
const unsigned short FACET_TYPE_MAXLENGTH = 3;
const unsigned short FACET_TYPE_PATTERN = 4;
const unsigned short FACET_TYPE_ENUMERATION = 5;
const unsigned short FACET_TYPE_WHITESPACE = 6;
const unsigned short FACET_TYPE_MAXINCLUSIVE = 7;
const unsigned short FACET_TYPE_MININCLUSIVE = 8;
const unsigned short FACET_TYPE_MAXEXCLUSIVE = 9;
const unsigned short FACET_TYPE_MINEXCLUSIVE = 10;
const unsigned short FACET_TYPE_TOTALDIGITS = 11;
const unsigned short FACET_TYPE_FRACTIONDIGITS = 12;
const unsigned short WHITESPACE_PRESERVE = 1;
const unsigned short WHITESPACE_REPLACE = 1;
const unsigned short WHITESPACE_COLLAPSE = 1;
readonly attribute unsigned short facetType;
readonly attribute AString value;
readonly attribute PRUint32 digitsValue; // For totalDigits and fractionDigits only
readonly attribute unsigned short whitespaceValue; // For whitespace only
readonly attribute boolean isfixed;
};

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

@ -0,0 +1,52 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla.
*
* The Initial Developer of the Original Code is Netscape
* Communications. Portions created by Netscape Communications are
* Copyright (C) 2001 by Netscape Communications. All
* Rights Reserved.
*
* Contributor(s):
* Vidur Apparao <vidur@netscape.com> (original author)
*/
#include "nsISupports.idl"
interface nsISchema;
interface nsIURI;
interface nsIDOMElement;
interface nsISchemaLoadListener;
[scriptable, uuid(3c14a032-6f4e-11d5-9b46-000064657374)]
interface nsISchemaLoader : nsISupports {
nsISchema load(in nsIURI schemaURI);
void loadAsync(in nsIURI schemaURI, in nsISchemaLoadListener listener);
nsISchema processSchemaElement(in nsIDOMElement element);
};
[scriptable, uuid(3c14a033-6f4e-11d5-9b46-000064657374)]
interface nsISchemaLoadListener : nsISupports {
void onError(in PRInt32 status,
in wstring statusMessage);
void onComplete(in nsISchema schema);
};
%{ C++
#define NS_SCHEMALOADER_CID \
{ /* 5adc10f0-74e1-11d5-9b49-00104bdf5339 */ \
0x5adc10f0, 0x74e1, 0x11d5, \
{0x9b, 0x49, 0x00, 0x10, 0x4b, 0xdf, 0x53, 0x39}}
#define NS_SCHEMALOADER_CONTRACTID "@mozilla.org/xmlextras/schemaloader;1"
%}

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

@ -0,0 +1,31 @@
#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
#
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS = public src
include $(topsrcdir)/config/rules.mk

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

@ -0,0 +1,47 @@
#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
#
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = xmlextras
LIBRARY_NAME = xmlextrasschema_s
REQUIRES = xpcom string dom caps necko xpconnect
CPPSRCS = \
nsSchema.cpp \
nsSchemaComponentBase.cpp \
nsSchemaSimpleTypes.cpp \
nsSchemaComplexType.cpp \
nsSchemaParticles.cpp \
nsSchemaAttributes.cpp \
nsSchemaLoader.cpp \
$(NULL)
# we don't want the shared lib, but we want to force the creation of a
# static lib.
FORCE_STATIC_LIB = 1
include $(topsrcdir)/config/rules.mk

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

@ -0,0 +1,448 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla.
*
* The Initial Developer of the Original Code is Netscape
* Communications. Portions created by Netscape Communications are
* Copyright (C) 2001 by Netscape Communications. All
* Rights Reserved.
*
* Contributor(s):
* Vidur Apparao <vidur@netscape.com> (original author)
*/
#include "nsSchemaPrivate.h"
////////////////////////////////////////////////////////////
//
// nsSchema implementation
//
////////////////////////////////////////////////////////////
nsSchema::nsSchema(const nsAReadableString& aTargetNamespace)
: mTargetNamespace(aTargetNamespace)
{
NS_INIT_ISUPPORTS();
}
nsSchema::~nsSchema()
{
}
NS_IMPL_ISUPPORTS2(nsSchema, nsISchema, nsISchemaComponent)
/* readonly attribute wstring targetNamespace; */
NS_IMETHODIMP
nsSchema::GetTargetNamespace(nsAWritableString& aTargetNamespace)
{
aTargetNamespace.Assign(mTargetNamespace);
return NS_OK;
}
/* void resolve (); */
NS_IMETHODIMP
nsSchema::Resolve()
{
nsresult rv;
PRUint32 i, count;
mTypes.Count(&count);
for (i = 0; i < count; i++) {
nsCOMPtr<nsISchemaType> type;
rv = mTypes.QueryElementAt(i, NS_GET_IID(nsISchemaType),
getter_AddRefs(type));
if (NS_SUCCEEDED(rv)) {
rv = type->Resolve();
NS_ENSURE_SUCCESS(rv, rv);
}
}
mAttributes.Count(&count);
for (i = 0; i < count; i++) {
nsCOMPtr<nsISchemaAttribute> attribute;
rv = mAttributes.QueryElementAt(i, NS_GET_IID(nsISchemaAttribute),
getter_AddRefs(attribute));
if (NS_SUCCEEDED(rv)) {
rv = attribute->Resolve();
NS_ENSURE_SUCCESS(rv, rv);
}
}
mElements.Count(&count);
for (i = 0; i < count; i++) {
nsCOMPtr<nsISchemaElement> element;
rv = mElements.QueryElementAt(i, NS_GET_IID(nsISchemaElement),
getter_AddRefs(element));
if (NS_SUCCEEDED(rv)) {
rv = element->Resolve();
NS_ENSURE_SUCCESS(rv, rv);
}
}
mAttributeGroups.Count(&count);
for (i = 0; i < count; i++) {
nsCOMPtr<nsISchemaAttributeGroup> attributeGroup;
rv = mAttributeGroups.QueryElementAt(i, NS_GET_IID(nsISchemaAttributeGroup),
getter_AddRefs(attributeGroup));
if (NS_SUCCEEDED(rv)) {
rv = attributeGroup->Resolve();
NS_ENSURE_SUCCESS(rv, rv);
}
}
mModelGroups.Count(&count);
for (i = 0; i < count; i++) {
nsCOMPtr<nsISchemaModelGroup> modelGroup;
rv = mModelGroups.QueryElementAt(i, NS_GET_IID(nsISchemaModelGroup),
getter_AddRefs(modelGroup));
if (NS_SUCCEEDED(rv)) {
rv = modelGroup->Resolve();
NS_ENSURE_SUCCESS(rv, rv);
}
}
return NS_OK;
}
/* void clear (); */
NS_IMETHODIMP
nsSchema::Clear()
{
nsresult rv;
PRUint32 i, count;
mTypes.Count(&count);
for (i = 0; i < count; i++) {
nsCOMPtr<nsISchemaType> type;
rv = mTypes.QueryElementAt(i, NS_GET_IID(nsISchemaType),
getter_AddRefs(type));
if (NS_SUCCEEDED(rv)) {
type->Clear();
}
}
mTypes.Clear();
mTypesHash.Reset();
mAttributes.Count(&count);
for (i = 0; i < count; i++) {
nsCOMPtr<nsISchemaAttribute> attribute;
rv = mAttributes.QueryElementAt(i, NS_GET_IID(nsISchemaAttribute),
getter_AddRefs(attribute));
if (NS_SUCCEEDED(rv)) {
attribute->Clear();
}
}
mAttributes.Clear();
mAttributesHash.Reset();
mElements.Count(&count);
for (i = 0; i < count; i++) {
nsCOMPtr<nsISchemaElement> element;
rv = mElements.QueryElementAt(i, NS_GET_IID(nsISchemaElement),
getter_AddRefs(element));
if (NS_SUCCEEDED(rv)) {
element->Clear();
}
}
mElements.Clear();
mElementsHash.Reset();
mAttributeGroups.Count(&count);
for (i = 0; i < count; i++) {
nsCOMPtr<nsISchemaAttributeGroup> attributeGroup;
rv = mAttributeGroups.QueryElementAt(i, NS_GET_IID(nsISchemaAttributeGroup),
getter_AddRefs(attributeGroup));
if (NS_SUCCEEDED(rv)) {
attributeGroup->Clear();
}
}
mAttributeGroups.Clear();
mAttributeGroupsHash.Reset();
mModelGroups.Count(&count);
for (i = 0; i < count; i++) {
nsCOMPtr<nsISchemaModelGroup> modelGroup;
rv = mModelGroups.QueryElementAt(i, NS_GET_IID(nsISchemaModelGroup),
getter_AddRefs(modelGroup));
if (NS_SUCCEEDED(rv)) {
modelGroup->Clear();
}
}
mModelGroups.Clear();
mModelGroupsHash.Reset();
return NS_OK;
}
/* readonly attribute PRUint32 typeCount; */
NS_IMETHODIMP
nsSchema::GetTypeCount(PRUint32 *aTypeCount)
{
NS_ENSURE_ARG_POINTER(aTypeCount);
return mTypes.Count(aTypeCount);
}
/* nsISchemaType getTypeByIndex (in PRUint32 index); */
NS_IMETHODIMP
nsSchema::GetTypeByIndex(PRUint32 index, nsISchemaType **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
return mTypes.QueryElementAt(index, NS_GET_IID(nsISchemaType),
(void**)_retval);
}
/* nsISchemaType getTypeByName (in wstring name); */
NS_IMETHODIMP
nsSchema::GetTypeByName(const nsAReadableString& name, nsISchemaType **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
nsStringKey key(name);
nsCOMPtr<nsISupports> sup = dont_AddRef(mTypesHash.Get(&key));
if (sup) {
return CallQueryInterface(sup, _retval);
}
return NS_OK;
}
/* readonly attribute PRUint32 attributeCount; */
NS_IMETHODIMP
nsSchema::GetAttributeCount(PRUint32 *aAttributeCount)
{
NS_ENSURE_ARG_POINTER(aAttributeCount);
return mAttributes.Count(aAttributeCount);
}
/* nsISchemaAttribute getAttributeByIndex (in PRUint32 index); */
NS_IMETHODIMP
nsSchema::GetAttributeByIndex(PRUint32 index, nsISchemaAttribute **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
return mAttributes.QueryElementAt(index, NS_GET_IID(nsISchemaAttribute),
(void**)_retval);
}
/* nsISchemaAttribute getAttributeByName (in wstring name); */
NS_IMETHODIMP
nsSchema::GetAttributeByName(const nsAReadableString& name, nsISchemaAttribute **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
nsStringKey key(name);
nsCOMPtr<nsISupports> sup = dont_AddRef(mAttributesHash.Get(&key));
if (sup) {
return CallQueryInterface(sup, _retval);
}
return NS_OK;
}
/* readonly attribute PRUint32 elementCount; */
NS_IMETHODIMP
nsSchema::GetElementCount(PRUint32 *aElementCount)
{
NS_ENSURE_ARG_POINTER(aElementCount);
return mElements.Count(aElementCount);
}
/* nsISchemaElement getElementByIndex (in PRUint32 index); */
NS_IMETHODIMP
nsSchema::GetElementByIndex(PRUint32 index, nsISchemaElement **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
return mElements.QueryElementAt(index, NS_GET_IID(nsISchemaElement),
(void**)_retval);
}
/* nsISchemaElement getElementByName (in wstring name); */
NS_IMETHODIMP
nsSchema::GetElementByName(const nsAReadableString& name,
nsISchemaElement **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
nsStringKey key(name);
nsCOMPtr<nsISupports> sup = dont_AddRef(mElementsHash.Get(&key));
if (sup) {
return CallQueryInterface(sup, _retval);
}
return NS_OK;
}
/* readonly attribute PRUint32 attributeGroupCount; */
NS_IMETHODIMP
nsSchema::GetAttributeGroupCount(PRUint32 *aAttributeGroupCount)
{
NS_ENSURE_ARG_POINTER(aAttributeGroupCount);
return mAttributeGroups.Count(aAttributeGroupCount);
}
/* nsISchemaAttributeGroup getAttributeGroupByIndex (in PRUint32 index); */
NS_IMETHODIMP
nsSchema::GetAttributeGroupByIndex(PRUint32 index, nsISchemaAttributeGroup **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
return mAttributeGroups.QueryElementAt(index,
NS_GET_IID(nsISchemaAttributeGroup),
(void**)_retval);
}
/* nsISchemaAttributeGroup getAttributeGroupByName (in wstring name); */
NS_IMETHODIMP
nsSchema::GetAttributeGroupByName(const nsAReadableString& name, nsISchemaAttributeGroup **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
nsStringKey key(name);
nsCOMPtr<nsISupports> sup = dont_AddRef(mAttributeGroupsHash.Get(&key));
if (sup) {
return CallQueryInterface(sup, _retval);
}
return NS_OK;
}
/* readonly attribute PRUint32 modelGroupCount; */
NS_IMETHODIMP
nsSchema::GetModelGroupCount(PRUint32 *aModelGroupCount)
{
NS_ENSURE_ARG_POINTER(aModelGroupCount);
return mModelGroups.Count(aModelGroupCount);
}
/* nsISchemaModelGroup getModelGroupByIndex (in PRUint32 index); */
NS_IMETHODIMP
nsSchema::GetModelGroupByIndex(PRUint32 index, nsISchemaModelGroup **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
return mModelGroups.QueryElementAt(index,
NS_GET_IID(nsISchemaModelGroup),
(void**)_retval);
}
/* nsISchemaModelGroup getModelGroupByName (in wstring name); */
NS_IMETHODIMP
nsSchema::GetModelGroupByName(const nsAReadableString& name, nsISchemaModelGroup **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
nsStringKey key(name);
nsCOMPtr<nsISupports> sup = dont_AddRef(mModelGroupsHash.Get(&key));
if (sup) {
return CallQueryInterface(sup, _retval);
}
return NS_OK;
}
NS_IMETHODIMP
nsSchema::AddType(nsISchemaType* aType)
{
NS_ENSURE_ARG_POINTER(aType);
nsAutoString name;
aType->GetName(name);
mTypes.AppendElement(aType);
nsStringKey key(name);
mTypesHash.Put(&key, aType);
return NS_OK;
}
NS_IMETHODIMP
nsSchema::AddAttribute(nsISchemaAttribute* aAttribute)
{
NS_ENSURE_ARG_POINTER(aAttribute);
nsAutoString name;
aAttribute->GetName(name);
mAttributes.AppendElement(aAttribute);
nsStringKey key(name);
mAttributesHash.Put(&key, aAttribute);
return NS_OK;
}
NS_IMETHODIMP
nsSchema::AddElement(nsISchemaElement* aElement)
{
NS_ENSURE_ARG_POINTER(aElement);
nsAutoString name;
aElement->GetName(name);
mElements.AppendElement(aElement);
nsStringKey key(name);
mElementsHash.Put(&key, aElement);
return NS_OK;
}
NS_IMETHODIMP
nsSchema::AddAttributeGroup(nsISchemaAttributeGroup* aAttributeGroup)
{
NS_ENSURE_ARG_POINTER(aAttributeGroup);
nsAutoString name;
aAttributeGroup->GetName(name);
mAttributeGroups.AppendElement(aAttributeGroup);
nsStringKey key(name);
mAttributeGroupsHash.Put(&key, aAttributeGroup);
return NS_OK;
}
NS_IMETHODIMP
nsSchema::AddModelGroup(nsISchemaModelGroup* aModelGroup)
{
NS_ENSURE_ARG_POINTER(aModelGroup);
nsAutoString name;
aModelGroup->GetName(name);
mModelGroups.AppendElement(aModelGroup);
nsStringKey key(name);
mModelGroupsHash.Put(&key, aModelGroup);
return NS_OK;
}

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

@ -0,0 +1,665 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla.
*
* The Initial Developer of the Original Code is Netscape
* Communications. Portions created by Netscape Communications are
* Copyright (C) 2001 by Netscape Communications. All
* Rights Reserved.
*
* Contributor(s):
* Vidur Apparao <vidur@netscape.com> (original author)
*/
#include "nsSchemaPrivate.h"
////////////////////////////////////////////////////////////
//
// nsSchemaAttribute implementation
//
////////////////////////////////////////////////////////////
nsSchemaAttribute::nsSchemaAttribute(nsISchema* aSchema,
const nsAReadableString& aName)
: nsSchemaComponentBase(aSchema), mName(aName)
{
NS_INIT_ISUPPORTS();
}
nsSchemaAttribute::~nsSchemaAttribute()
{
}
NS_IMPL_ISUPPORTS3(nsSchemaAttribute,
nsISchemaComponent,
nsISchemaAttributeComponent,
nsISchemaAttribute)
/* void resolve (); */
NS_IMETHODIMP
nsSchemaAttribute::Resolve()
{
return NS_OK;
}
/* void clear (); */
NS_IMETHODIMP
nsSchemaAttribute::Clear()
{
if (mIsClearing) {
return NS_OK;
}
mIsClearing = PR_TRUE;
mType->Clear();
mType = nsnull;
mIsClearing = PR_FALSE;
return NS_OK;
}
/* readonly attribute AString name; */
NS_IMETHODIMP
nsSchemaAttribute::GetName(nsAWritableString & aName)
{
aName.Assign(mName);
return NS_OK;
}
/* readonly attribute unsigned short componentType; */
NS_IMETHODIMP
nsSchemaAttribute::GetComponentType(PRUint16 *aComponentType)
{
NS_ENSURE_ARG_POINTER(aComponentType);
*aComponentType = nsISchemaAttributeComponent::COMPONENT_TYPE_ATTRIBUTE;
return NS_OK;
}
/* readonly attribute nsISchemaSimpleType type; */
NS_IMETHODIMP
nsSchemaAttribute::GetType(nsISchemaSimpleType * *aType)
{
NS_ENSURE_ARG_POINTER(aType);
*aType = mType;
NS_IF_ADDREF(*aType);
return NS_OK;
}
/* readonly attribute AString defaultValue; */
NS_IMETHODIMP
nsSchemaAttribute::GetDefaultValue(nsAWritableString & aDefaultValue)
{
aDefaultValue.Assign(mDefaultValue);
return NS_OK;
}
/* readonly attribute AString fixedValue; */
NS_IMETHODIMP
nsSchemaAttribute::GetFixedValue(nsAWritableString & aFixedValue)
{
aFixedValue.Assign(mFixedValue);
return NS_OK;
}
/* readonly attribute unsigned short use; */
NS_IMETHODIMP
nsSchemaAttribute::GetUse(PRUint16 *aUse)
{
NS_ENSURE_ARG_POINTER(aUse);
*aUse = mUse;
return NS_OK;
}
NS_IMETHODIMP
nsSchemaAttribute::SetType(nsISchemaSimpleType* aType)
{
NS_ENSURE_ARG(aType);
mType = aType;
return NS_OK;
}
NS_IMETHODIMP
nsSchemaAttribute::SetConstraints(const nsAReadableString& aDefaultValue,
const nsAReadableString& aFixedValue)
{
mDefaultValue.Assign(aDefaultValue);
mFixedValue.Assign(aFixedValue);
return NS_OK;
}
NS_IMETHODIMP
nsSchemaAttribute::SetUse(PRUint16 aUse)
{
mUse = aUse;
return NS_OK;
}
////////////////////////////////////////////////////////////
//
// nsSchemaAttributeRef implementation
//
////////////////////////////////////////////////////////////
nsSchemaAttributeRef::nsSchemaAttributeRef(nsISchema* aSchema,
const nsAReadableString& aRef)
: nsSchemaComponentBase(aSchema), mRef(aRef)
{
NS_INIT_ISUPPORTS();
}
nsSchemaAttributeRef::~nsSchemaAttributeRef()
{
}
NS_IMPL_ISUPPORTS3(nsSchemaAttributeRef,
nsISchemaComponent,
nsISchemaAttributeComponent,
nsISchemaAttribute)
/* void resolve (); */
NS_IMETHODIMP
nsSchemaAttributeRef::Resolve()
{
nsresult rv = NS_OK;
if (mIsResolving) {
return NS_OK;
}
mIsResolving = PR_TRUE;
if (!mAttribute && mSchema) {
mSchema->GetAttributeByName(mRef, getter_AddRefs(mAttribute));
}
if (mAttribute) {
rv = mAttribute->Resolve();
}
mIsResolving = PR_FALSE;
return rv;
}
/* void clear (); */
NS_IMETHODIMP
nsSchemaAttributeRef::Clear()
{
if (mIsClearing) {
return NS_OK;
}
mIsClearing = PR_TRUE;
mAttribute->Clear();
mAttribute = nsnull;
mIsClearing = PR_FALSE;
return NS_OK;
}
/* readonly attribute AString name; */
NS_IMETHODIMP
nsSchemaAttributeRef::GetName(nsAWritableString & aName)
{
if (!mAttribute) {
return NS_ERROR_NOT_INITIALIZED;
}
return mAttribute->GetName(aName);
}
/* readonly attribute unsigned short componentType; */
NS_IMETHODIMP
nsSchemaAttributeRef::GetComponentType(PRUint16 *aComponentType)
{
NS_ENSURE_ARG_POINTER(aComponentType);
*aComponentType = nsISchemaAttributeComponent::COMPONENT_TYPE_ATTRIBUTE;
return NS_OK;
}
/* readonly attribute nsISchemaSimpleType type; */
NS_IMETHODIMP
nsSchemaAttributeRef::GetType(nsISchemaSimpleType * *aType)
{
NS_ENSURE_ARG_POINTER(aType);
if (!mAttribute) {
return NS_ERROR_NOT_INITIALIZED;
}
return mAttribute->GetType(aType);
}
/* readonly attribute AString defaultValue; */
NS_IMETHODIMP
nsSchemaAttributeRef::GetDefaultValue(nsAWritableString & aDefaultValue)
{
aDefaultValue.Assign(mDefaultValue);
return NS_OK;
}
/* readonly attribute AString fixedValue; */
NS_IMETHODIMP
nsSchemaAttributeRef::GetFixedValue(nsAWritableString & aFixedValue)
{
aFixedValue.Assign(mFixedValue);
return NS_OK;
}
/* readonly attribute unsigned short use; */
NS_IMETHODIMP
nsSchemaAttributeRef::GetUse(PRUint16 *aUse)
{
NS_ENSURE_ARG_POINTER(aUse);
*aUse = mUse;
return NS_OK;
}
NS_IMETHODIMP
nsSchemaAttributeRef::SetConstraints(const nsAReadableString& aDefaultValue,
const nsAReadableString& aFixedValue)
{
mDefaultValue.Assign(aDefaultValue);
mFixedValue.Assign(aFixedValue);
return NS_OK;
}
NS_IMETHODIMP
nsSchemaAttributeRef::SetUse(PRUint16 aUse)
{
mUse = aUse;
return NS_OK;
}
////////////////////////////////////////////////////////////
//
// nsSchemaAttributeGroup implementation
//
////////////////////////////////////////////////////////////
nsSchemaAttributeGroup::nsSchemaAttributeGroup(nsISchema* aSchema,
const nsAReadableString& aName)
: nsSchemaComponentBase(aSchema), mName(aName)
{
NS_INIT_ISUPPORTS();
}
nsSchemaAttributeGroup::~nsSchemaAttributeGroup()
{
}
NS_IMPL_ISUPPORTS3(nsSchemaAttributeGroup,
nsISchemaComponent,
nsISchemaAttributeComponent,
nsISchemaAttributeGroup)
/* void resolve (); */
NS_IMETHODIMP
nsSchemaAttributeGroup::Resolve()
{
if (mIsResolving) {
return NS_OK;
}
mIsResolving = PR_TRUE;
nsresult rv;
PRUint32 i, count;
mAttributes.Count(&count);
for (i = 0; i < count; i++) {
nsCOMPtr<nsISchemaAttributeComponent> attribute;
rv = mAttributes.QueryElementAt(i, NS_GET_IID(nsISchemaAttributeComponent),
getter_AddRefs(attribute));
if (NS_SUCCEEDED(rv)) {
rv = attribute->Resolve();
if (NS_FAILED(rv)) {
mIsResolving = PR_FALSE;
return rv;
}
}
}
mIsResolving = PR_FALSE;
return NS_OK;
}
/* void clear (); */
NS_IMETHODIMP
nsSchemaAttributeGroup::Clear()
{
if (mIsClearing) {
return NS_OK;
}
mIsClearing = PR_TRUE;
nsresult rv;
PRUint32 i, count;
mAttributes.Count(&count);
for (i = 0; i < count; i++) {
nsCOMPtr<nsISchemaAttributeComponent> attribute;
rv = mAttributes.QueryElementAt(i, NS_GET_IID(nsISchemaAttributeComponent),
getter_AddRefs(attribute));
if (NS_SUCCEEDED(rv)) {
attribute->Clear();
}
}
mAttributes.Clear();
mAttributesHash.Reset();
mIsClearing = PR_FALSE;
return NS_OK;
}
/* readonly attribute AString name; */
NS_IMETHODIMP
nsSchemaAttributeGroup::GetName(nsAWritableString & aName)
{
aName.Assign(mName);
return NS_OK;
}
/* readonly attribute unsigned short componentType; */
NS_IMETHODIMP
nsSchemaAttributeGroup::GetComponentType(PRUint16 *aComponentType)
{
NS_ENSURE_ARG_POINTER(aComponentType);
*aComponentType = nsISchemaAttributeComponent::COMPONENT_TYPE_GROUP;
return NS_OK;
}
/* readonly attribute PRUint32 attributeCount; */
NS_IMETHODIMP
nsSchemaAttributeGroup::GetAttributeCount(PRUint32 *aAttributeCount)
{
NS_ENSURE_ARG_POINTER(aAttributeCount);
return mAttributes.Count(aAttributeCount);
}
/* nsISchemaAttributeComponent getAttributeByIndex (in PRUint32 index); */
NS_IMETHODIMP
nsSchemaAttributeGroup::GetAttributeByIndex(PRUint32 index,
nsISchemaAttributeComponent **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
return mAttributes.QueryElementAt(index,
NS_GET_IID(nsISchemaAttributeComponent),
(void**)_retval);
}
/* nsISchemaAttributeComponent getAttributeByName (in AString name); */
NS_IMETHODIMP
nsSchemaAttributeGroup::GetAttributeByName(const nsAReadableString & name,
nsISchemaAttributeComponent **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
nsStringKey key(name);
nsCOMPtr<nsISupports> sup = dont_AddRef(mAttributesHash.Get(&key));
if (sup) {
return CallQueryInterface(sup, _retval);
}
return NS_OK;
}
NS_IMETHODIMP
nsSchemaAttributeGroup::AddAttribute(nsISchemaAttributeComponent* aAttribute)
{
NS_ENSURE_ARG_POINTER(aAttribute);
nsAutoString name;
aAttribute->GetName(name);
mAttributes.AppendElement(aAttribute);
nsStringKey key(name);
mAttributesHash.Put(&key, aAttribute);
return NS_OK;
}
////////////////////////////////////////////////////////////
//
// nsSchemaAttributeGroupRef implementation
//
////////////////////////////////////////////////////////////
nsSchemaAttributeGroupRef::nsSchemaAttributeGroupRef(nsISchema* aSchema,
const nsAReadableString& aRef)
: nsSchemaComponentBase(aSchema), mRef(aRef)
{
NS_INIT_ISUPPORTS();
}
nsSchemaAttributeGroupRef::~nsSchemaAttributeGroupRef()
{
}
NS_IMPL_ISUPPORTS3(nsSchemaAttributeGroupRef,
nsISchemaComponent,
nsISchemaAttributeComponent,
nsISchemaAttributeGroup)
/* void resolve (); */
NS_IMETHODIMP
nsSchemaAttributeGroupRef::Resolve()
{
nsresult rv = NS_OK;
if (mIsResolving) {
return NS_OK;
}
mIsResolving = PR_TRUE;
if (!mAttributeGroup && mSchema) {
mSchema->GetAttributeGroupByName(mRef, getter_AddRefs(mAttributeGroup));
}
if (mAttributeGroup) {
rv = mAttributeGroup->Resolve();
}
mIsResolving = PR_FALSE;
return rv;
}
/* void clear (); */
NS_IMETHODIMP
nsSchemaAttributeGroupRef::Clear()
{
if (mIsClearing) {
return NS_OK;
}
mIsClearing = PR_TRUE;
mAttributeGroup->Clear();
mAttributeGroup = nsnull;
mIsClearing = PR_FALSE;
return NS_OK;
}
/* readonly attribute AString name; */
NS_IMETHODIMP
nsSchemaAttributeGroupRef::GetName(nsAWritableString & aName)
{
if (!mAttributeGroup) {
return NS_ERROR_NOT_INITIALIZED;
}
return mAttributeGroup->GetName(aName);
}
/* readonly attribute unsigned short componentType; */
NS_IMETHODIMP
nsSchemaAttributeGroupRef::GetComponentType(PRUint16 *aComponentType)
{
NS_ENSURE_ARG_POINTER(aComponentType);
*aComponentType = nsISchemaAttributeComponent::COMPONENT_TYPE_GROUP;
return NS_OK;
}
/* readonly attribute PRUint32 attributeCount; */
NS_IMETHODIMP
nsSchemaAttributeGroupRef::GetAttributeCount(PRUint32 *aAttributeCount)
{
NS_ENSURE_ARG_POINTER(aAttributeCount);
if (!mAttributeGroup) {
return NS_ERROR_NOT_INITIALIZED;
}
return mAttributeGroup->GetAttributeCount(aAttributeCount);
}
/* nsISchemaAttributeComponent getAttributeByIndex (in PRUint32 index); */
NS_IMETHODIMP
nsSchemaAttributeGroupRef::GetAttributeByIndex(PRUint32 index,
nsISchemaAttributeComponent **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
if (!mAttributeGroup) {
return NS_ERROR_NOT_INITIALIZED;
}
return mAttributeGroup->GetAttributeByIndex(index, _retval);
}
/* nsISchemaAttributeComponent getAttributeByName (in AString name); */
NS_IMETHODIMP
nsSchemaAttributeGroupRef::GetAttributeByName(const nsAReadableString & name,
nsISchemaAttributeComponent **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
if (!mAttributeGroup) {
return NS_ERROR_NOT_INITIALIZED;
}
return mAttributeGroup->GetAttributeByName(name, _retval);
}
////////////////////////////////////////////////////////////
//
// nsSchemaAnyAttribute implementation
//
////////////////////////////////////////////////////////////
nsSchemaAnyAttribute::nsSchemaAnyAttribute(nsISchema* aSchema)
: nsSchemaComponentBase(aSchema), mProcess(PROCESS_STRICT)
{
NS_INIT_ISUPPORTS();
}
nsSchemaAnyAttribute::~nsSchemaAnyAttribute()
{
}
NS_IMPL_ISUPPORTS3(nsSchemaAnyAttribute,
nsISchemaComponent,
nsISchemaAttributeComponent,
nsISchemaAnyAttribute)
/* void resolve (); */
NS_IMETHODIMP
nsSchemaAnyAttribute::Resolve()
{
return NS_OK;
}
/* void clear (); */
NS_IMETHODIMP
nsSchemaAnyAttribute::Clear()
{
return NS_OK;
}
/* readonly attribute unsigned short componentType; */
NS_IMETHODIMP
nsSchemaAnyAttribute::GetComponentType(PRUint16 *aComponentType)
{
NS_ENSURE_ARG_POINTER(aComponentType);
*aComponentType = nsISchemaAttributeComponent::COMPONENT_TYPE_ANY;
return NS_OK;
}
/* readonly attribute AString name; */
NS_IMETHODIMP
nsSchemaAnyAttribute::GetName(nsAWritableString & aName)
{
aName.Assign(NS_LITERAL_STRING("anyAttribute"));
return NS_OK;
}
/* readonly attribute unsigned short process; */
NS_IMETHODIMP
nsSchemaAnyAttribute::GetProcess(PRUint16 *aProcess)
{
NS_ENSURE_ARG_POINTER(aProcess);
*aProcess = mProcess;
return NS_OK;
}
/* readonly attribute AString namespace; */
NS_IMETHODIMP
nsSchemaAnyAttribute::GetNamespace(nsAWritableString & aNamespace)
{
aNamespace.Assign(mNamespace);
return NS_OK;
}
NS_IMETHODIMP
nsSchemaAnyAttribute::SetProcess(PRUint16 aProcess)
{
mProcess = aProcess;
return NS_OK;
}
NS_IMETHODIMP
nsSchemaAnyAttribute::SetNamespace(const nsAReadableString& aNamespace)
{
mNamespace.Assign(aNamespace);
return NS_OK;
}

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

@ -0,0 +1,273 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla.
*
* The Initial Developer of the Original Code is Netscape
* Communications. Portions created by Netscape Communications are
* Copyright (C) 2001 by Netscape Communications. All
* Rights Reserved.
*
* Contributor(s):
* Vidur Apparao <vidur@netscape.com> (original author)
*/
#include "nsSchemaPrivate.h"
////////////////////////////////////////////////////////////
//
// nsSchemaComplexType implementation
//
////////////////////////////////////////////////////////////
nsSchemaComplexType::nsSchemaComplexType(nsISchema* aSchema,
const nsAReadableString& aName,
PRBool aAbstract)
: nsSchemaComponentBase(aSchema), mName(aName), mAbstract(aAbstract),
mContentModel(CONTENT_MODEL_ELEMENT_ONLY),
mDerivation(DERIVATION_SELF_CONTAINED)
{
NS_INIT_ISUPPORTS();
}
nsSchemaComplexType::~nsSchemaComplexType()
{
}
NS_IMPL_ISUPPORTS3(nsSchemaComplexType,
nsISchemaComponent,
nsISchemaType,
nsISchemaComplexType)
/* void resolve (); */
NS_IMETHODIMP
nsSchemaComplexType::Resolve()
{
if (mIsResolving) {
return NS_OK;
}
mIsResolving = PR_TRUE;
nsresult rv;
PRUint32 i, count;
mAttributes.Count(&count);
for (i = 0; i < count; i++) {
nsCOMPtr<nsISchemaAttributeComponent> attribute;
rv = mAttributes.QueryElementAt(i, NS_GET_IID(nsISchemaAttributeComponent),
getter_AddRefs(attribute));
if (NS_SUCCEEDED(rv)) {
rv = attribute->Resolve();
if (NS_FAILED(rv)) {
mIsResolving = PR_FALSE;
return rv;
}
}
}
mIsResolving = PR_FALSE;
return NS_OK;
}
/* void clear (); */
NS_IMETHODIMP
nsSchemaComplexType::Clear()
{
if (mIsClearing) {
return NS_OK;
}
mIsClearing = PR_TRUE;
if (mBaseType) {
mBaseType->Clear();
mBaseType = nsnull;
}
if (mModelGroup) {
mModelGroup->Clear();
mModelGroup = nsnull;
}
nsresult rv;
PRUint32 i, count;
mAttributes.Count(&count);
for (i = 0; i < count; i++) {
nsCOMPtr<nsISchemaAttributeComponent> attribute;
rv = mAttributes.QueryElementAt(i, NS_GET_IID(nsISchemaAttributeComponent),
getter_AddRefs(attribute));
if (NS_SUCCEEDED(rv)) {
attribute->Clear();
}
}
mAttributes.Clear();
mAttributesHash.Reset();
mIsClearing = PR_FALSE;
return NS_OK;
}
/* readonly attribute wstring name; */
NS_IMETHODIMP
nsSchemaComplexType::GetName(nsAWritableString& aName)
{
aName.Assign(mName);
return NS_OK;
}
/* readonly attribute unsigned short schemaType; */
NS_IMETHODIMP
nsSchemaComplexType::GetSchemaType(PRUint16 *aSchemaType)
{
NS_ENSURE_ARG_POINTER(aSchemaType);
*aSchemaType = nsISchemaType::SCHEMA_TYPE_COMPLEX;
return NS_OK;
}
/* readonly attribute unsigned short contentModel; */
NS_IMETHODIMP
nsSchemaComplexType::GetContentModel(PRUint16 *aContentModel)
{
NS_ENSURE_ARG_POINTER(aContentModel);
*aContentModel = mContentModel;
return NS_OK;
}
/* readonly attribute unsigned short derivation; */
NS_IMETHODIMP
nsSchemaComplexType::GetDerivation(PRUint16 *aDerivation)
{
NS_ENSURE_ARG_POINTER(aDerivation);
*aDerivation = mDerivation;
return NS_OK;
}
/* readonly attribute nsISchemaType baseType; */
NS_IMETHODIMP
nsSchemaComplexType::GetBaseType(nsISchemaType * *aBaseType)
{
NS_ENSURE_ARG_POINTER(aBaseType);
*aBaseType = mBaseType;
NS_IF_ADDREF(*aBaseType);
return NS_OK;
}
/* readonly attribute nsISchemaModelGroup modelGroup; */
NS_IMETHODIMP
nsSchemaComplexType::GetModelGroup(nsISchemaModelGroup * *aModelGroup)
{
NS_ENSURE_ARG_POINTER(aModelGroup);
*aModelGroup = mModelGroup;
NS_IF_ADDREF(*aModelGroup);
return NS_OK;
}
/* readonly attribute PRUint32 attributeCount; */
NS_IMETHODIMP
nsSchemaComplexType::GetAttributeCount(PRUint32 *aAttributeCount)
{
NS_ENSURE_ARG_POINTER(aAttributeCount);
return mAttributes.Count(aAttributeCount);
}
/* nsISchemaAttributeComponent getAttributeByIndex (in PRUint32 index); */
NS_IMETHODIMP
nsSchemaComplexType::GetAttributeByIndex(PRUint32 index,
nsISchemaAttributeComponent **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
return mAttributes.QueryElementAt(index,
NS_GET_IID(nsISchemaAttributeComponent),
(void**)_retval);
}
/* nsISchemaAttributeComponent getAttributeByName (in AString name); */
NS_IMETHODIMP
nsSchemaComplexType::GetAttributeByName(const nsAReadableString& name,
nsISchemaAttributeComponent **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
nsStringKey key(name);
nsCOMPtr<nsISupports> sup = dont_AddRef(mAttributesHash.Get(&key));
if (sup) {
return CallQueryInterface(sup, _retval);
}
return NS_OK;
}
/* readonly attribute boolean abstract; */
NS_IMETHODIMP
nsSchemaComplexType::GetAbstract(PRBool *aAbstract)
{
NS_ENSURE_ARG_POINTER(aAbstract);
*aAbstract = mAbstract;
return NS_OK;
}
NS_IMETHODIMP
nsSchemaComplexType::SetContentModel(PRUint16 aContentModel)
{
mContentModel = aContentModel;
return NS_OK;
}
NS_IMETHODIMP
nsSchemaComplexType::SetDerivation(PRUint16 aDerivation,
nsISchemaType* aBaseType)
{
mDerivation = aDerivation;
mBaseType = aBaseType;
return NS_OK;
}
NS_IMETHODIMP
nsSchemaComplexType::SetModelGroup(nsISchemaModelGroup* aModelGroup)
{
mModelGroup = aModelGroup;
return NS_OK;
}
NS_IMETHODIMP
nsSchemaComplexType::AddAttribute(nsISchemaAttributeComponent* aAttribute)
{
NS_ENSURE_ARG_POINTER(aAttribute);
nsAutoString name;
aAttribute->GetName(name);
mAttributes.AppendElement(aAttribute);
nsStringKey key(name);
mAttributesHash.Put(&key, aAttribute);
return NS_OK;
}

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

@ -0,0 +1,51 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla.
*
* The Initial Developer of the Original Code is Netscape
* Communications. Portions created by Netscape Communications are
* Copyright (C) 2001 by Netscape Communications. All
* Rights Reserved.
*
* Contributor(s):
* Vidur Apparao <vidur@netscape.com> (original author)
*/
#include "nsSchemaPrivate.h"
////////////////////////////////////////////////////////////
//
// nsSchemaComponentBase implementation
//
////////////////////////////////////////////////////////////
nsSchemaComponentBase::nsSchemaComponentBase(nsISchema* aSchema)
: mSchema(aSchema), mIsResolving(PR_FALSE), mIsClearing(PR_FALSE)
{
}
nsSchemaComponentBase::~nsSchemaComponentBase()
{
mSchema = nsnull;
}
/* readonly attribute wstring targetNamespace; */
NS_IMETHODIMP
nsSchemaComponentBase::GetTargetNamespace(nsAWritableString& aTargetNamespace)
{
if (mSchema) {
return mSchema->GetTargetNamespace(aTargetNamespace);
}
aTargetNamespace.Truncate();
return NS_OK;
}

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

@ -0,0 +1,78 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla.
*
* The Initial Developer of the Original Code is Netscape
* Communications. Portions created by Netscape Communications are
* Copyright (C) 2001 by Netscape Communications. All
* Rights Reserved.
*
* Contributor(s):
* Vidur Apparao <vidur@netscape.com> (original author)
*/
#include "nsSchemaPrivate.h"
#include "nsSchemaLoader.h"
nsSchemaLoader::nsSchemaLoader()
{
NS_INIT_ISUPPORTS();
}
nsSchemaLoader::~nsSchemaLoader()
{
}
NS_IMPL_ISUPPORTS1(nsSchemaLoader, nsISchemaLoader)
/* nsISchema load (in nsIURI schemaURI); */
NS_IMETHODIMP
nsSchemaLoader::Load(nsIURI *schemaURI, nsISchema **_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void loadAsync (in nsIURI schemaURI, in nsISchemaLoadListener listener); */
NS_IMETHODIMP
nsSchemaLoader::LoadAsync(nsIURI *schemaURI, nsISchemaLoadListener *listener)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* nsISchema processSchemaElement (in nsIDOMElement element); */
NS_IMETHODIMP
nsSchemaLoader::ProcessSchemaElement(nsIDOMElement *element,
nsISchema **_retval)
{
nsAutoString dummy;
nsSchema* schema = new nsSchema(dummy);
nsSchemaBuiltinType* bt = new nsSchemaBuiltinType(1);
nsSchemaListType* lt = new nsSchemaListType(schema, dummy);
nsSchemaUnionType* ut = new nsSchemaUnionType(schema, dummy);
nsSchemaRestrictionType* rt = new nsSchemaRestrictionType(schema, dummy);
nsSchemaComplexType* ct = new nsSchemaComplexType(schema, dummy, PR_FALSE);
nsSchemaModelGroup* mg = new nsSchemaModelGroup(schema, dummy, 1);
nsSchemaModelGroupRef* mgr = new nsSchemaModelGroupRef(schema, dummy);
nsSchemaAnyParticle* ap = new nsSchemaAnyParticle(schema);
nsSchemaElement* el = new nsSchemaElement(schema, dummy);
nsSchemaElementRef* elr = new nsSchemaElementRef(schema, dummy);
nsSchemaAttribute* att = new nsSchemaAttribute(schema, dummy);
nsSchemaAttributeRef* attr = new nsSchemaAttributeRef(schema, dummy);
nsSchemaAttributeGroup* attg = new nsSchemaAttributeGroup(schema, dummy);
nsSchemaAttributeGroupRef* attgr = new nsSchemaAttributeGroupRef(schema, dummy);
nsSchemaAnyAttribute* ant = new nsSchemaAnyAttribute(schema);
nsSchemaFacet* fac = new nsSchemaFacet(schema, 1, PR_FALSE);
return NS_OK;
}

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

@ -0,0 +1,40 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla.
*
* The Initial Developer of the Original Code is Netscape
* Communications. Portions created by Netscape Communications are
* Copyright (C) 2001 by Netscape Communications. All
* Rights Reserved.
*
* Contributor(s):
* Vidur Apparao <vidur@netscape.com> (original author)
*/
#ifndef __nsSchemaLoader_h__
#define __nsSchemaLoader_h__
#include "nsISchemaLoader.h"
class nsSchemaLoader : public nsISchemaLoader
{
public:
nsSchemaLoader();
virtual ~nsSchemaLoader();
NS_DECL_ISUPPORTS
NS_DECL_NSISCHEMALOADER
};
#endif // __nsSchemaLoader_h__

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

@ -0,0 +1,723 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla.
*
* The Initial Developer of the Original Code is Netscape
* Communications. Portions created by Netscape Communications are
* Copyright (C) 2001 by Netscape Communications. All
* Rights Reserved.
*
* Contributor(s):
* Vidur Apparao <vidur@netscape.com> (original author)
*/
#include "nsSchemaPrivate.h"
////////////////////////////////////////////////////////////
//
// nsSchemaParticleBase implementation
//
////////////////////////////////////////////////////////////
nsSchemaParticleBase::nsSchemaParticleBase(nsISchema* aSchema)
: nsSchemaComponentBase(aSchema), mMinOccurs(1), mMaxOccurs(1)
{
}
nsSchemaParticleBase::~nsSchemaParticleBase()
{
}
NS_IMETHODIMP
nsSchemaParticleBase::GetMinOccurs(PRUint32 *aMinOccurs)
{
NS_ENSURE_ARG_POINTER(aMinOccurs);
*aMinOccurs = mMinOccurs;
return NS_OK;
}
NS_IMETHODIMP
nsSchemaParticleBase::GetMaxOccurs(PRUint32 *aMaxOccurs)
{
NS_ENSURE_ARG_POINTER(aMaxOccurs);
*aMaxOccurs = mMaxOccurs;
return NS_OK;
}
NS_IMETHODIMP
nsSchemaParticleBase::SetMinOccurs(PRUint32 aMinOccurs)
{
mMinOccurs = aMinOccurs;
if (mMaxOccurs < mMinOccurs) {
mMaxOccurs = mMinOccurs;
}
return NS_OK;
}
NS_IMETHODIMP
nsSchemaParticleBase::SetMaxOccurs(PRUint32 aMaxOccurs)
{
mMaxOccurs = aMaxOccurs;
if (mMinOccurs > mMaxOccurs) {
mMinOccurs = mMaxOccurs;
}
return NS_OK;
}
////////////////////////////////////////////////////////////
//
// nsSchemaModelGroup implementation
//
////////////////////////////////////////////////////////////
nsSchemaModelGroup::nsSchemaModelGroup(nsISchema* aSchema,
const nsAReadableString& aName,
PRUint16 aCompositor)
: nsSchemaParticleBase(aSchema), mName(aName), mCompositor(aCompositor)
{
NS_INIT_ISUPPORTS();
}
nsSchemaModelGroup::~nsSchemaModelGroup()
{
}
NS_IMPL_ISUPPORTS3(nsSchemaModelGroup,
nsISchemaComponent,
nsISchemaParticle,
nsISchemaModelGroup)
/* void resolve (); */
NS_IMETHODIMP
nsSchemaModelGroup::Resolve()
{
if (mIsResolving) {
return NS_OK;
}
mIsResolving = PR_TRUE;
nsresult rv;
PRUint32 i, count;
mParticles.Count(&count);
for (i = 0; i < count; i++) {
nsCOMPtr<nsISchemaParticle> particle;
rv = mParticles.QueryElementAt(i, NS_GET_IID(nsISchemaParticle),
getter_AddRefs(particle));
if (NS_SUCCEEDED(rv)) {
rv = particle->Resolve();
if (NS_FAILED(rv)) {
mIsResolving = PR_FALSE;
return rv;
}
}
}
mIsResolving = PR_FALSE;
return NS_OK;
}
/* void clear (); */
NS_IMETHODIMP
nsSchemaModelGroup::Clear()
{
if (mIsClearing) {
return NS_OK;
}
mIsClearing = PR_TRUE;
nsresult rv;
PRUint32 i, count;
mParticles.Count(&count);
for (i = 0; i < count; i++) {
nsCOMPtr<nsISchemaParticle> particle;
rv = mParticles.QueryElementAt(i, NS_GET_IID(nsISchemaParticle),
getter_AddRefs(particle));
if (NS_SUCCEEDED(rv)) {
particle->Clear();
}
}
mIsClearing = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP
nsSchemaModelGroup::GetParticleType(PRUint16 *aParticleType)
{
NS_ENSURE_ARG_POINTER(aParticleType);
*aParticleType = nsISchemaParticle::PARTICLE_TYPE_MODEL_GROUP;
return NS_OK;
}
NS_IMETHODIMP
nsSchemaModelGroup::GetName(nsAWritableString& aName)
{
aName.Assign(mName);
return NS_OK;
}
/* readonly attribute unsigned short compositor; */
NS_IMETHODIMP
nsSchemaModelGroup::GetCompositor(PRUint16 *aCompositor)
{
NS_ENSURE_ARG_POINTER(aCompositor);
*aCompositor = mCompositor;
return NS_OK;
}
/* readonly attribute PRUint32 particleCount; */
NS_IMETHODIMP
nsSchemaModelGroup::GetParticleCount(PRUint32 *aParticleCount)
{
NS_ENSURE_ARG_POINTER(aParticleCount);
return mParticles.Count(aParticleCount);
}
/* nsISchemaParticle getParticle (in PRUint32 index); */
NS_IMETHODIMP
nsSchemaModelGroup::GetParticle(PRUint32 index, nsISchemaParticle **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
return mParticles.QueryElementAt(index, NS_GET_IID(nsISchemaParticle),
(void**)_retval);
}
NS_IMETHODIMP
nsSchemaModelGroup::AddParticle(nsISchemaParticle* aParticle)
{
NS_ENSURE_ARG_POINTER(aParticle);
return mParticles.AppendElement(aParticle);
}
////////////////////////////////////////////////////////////
//
// nsSchemaModelGroupRef implementation
//
////////////////////////////////////////////////////////////
nsSchemaModelGroupRef::nsSchemaModelGroupRef(nsISchema* aSchema,
const nsAReadableString& aRef)
: nsSchemaParticleBase(aSchema), mRef(aRef)
{
NS_INIT_ISUPPORTS();
}
nsSchemaModelGroupRef::~nsSchemaModelGroupRef()
{
}
NS_IMPL_ISUPPORTS3(nsSchemaModelGroupRef,
nsISchemaComponent,
nsISchemaParticle,
nsISchemaModelGroup)
/* void resolve (); */
NS_IMETHODIMP
nsSchemaModelGroupRef::Resolve()
{
nsresult rv = NS_OK;
if (mIsResolving) {
return NS_OK;
}
mIsResolving = PR_TRUE;
if (!mModelGroup && mSchema) {
mSchema->GetModelGroupByName(mRef, getter_AddRefs(mModelGroup));
}
if (mModelGroup) {
rv = mModelGroup->Resolve();
}
mIsResolving = PR_FALSE;
return rv;
}
/* void clear (); */
NS_IMETHODIMP
nsSchemaModelGroupRef::Clear()
{
if (mIsClearing) {
return NS_OK;
}
mIsClearing = PR_TRUE;
if (mModelGroup) {
mModelGroup->Clear();
mModelGroup = nsnull;
}
mIsClearing = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP
nsSchemaModelGroupRef::GetParticleType(PRUint16 *aParticleType)
{
NS_ENSURE_ARG_POINTER(aParticleType);
*aParticleType = nsISchemaParticle::PARTICLE_TYPE_MODEL_GROUP;
return NS_OK;
}
NS_IMETHODIMP
nsSchemaModelGroupRef::GetName(nsAWritableString& aName)
{
if (!mModelGroup) {
return NS_ERROR_NOT_INITIALIZED;
}
return mModelGroup->GetName(aName);
}
/* readonly attribute unsigned short compositor; */
NS_IMETHODIMP
nsSchemaModelGroupRef::GetCompositor(PRUint16 *aCompositor)
{
NS_ENSURE_ARG_POINTER(aCompositor);
if (!mModelGroup) {
return NS_ERROR_NOT_INITIALIZED;
}
return mModelGroup->GetCompositor(aCompositor);
}
/* readonly attribute PRUint32 particleCount; */
NS_IMETHODIMP
nsSchemaModelGroupRef::GetParticleCount(PRUint32 *aParticleCount)
{
NS_ENSURE_ARG_POINTER(aParticleCount);
if (!mModelGroup) {
return NS_ERROR_NOT_INITIALIZED;
}
return mModelGroup->GetParticleCount(aParticleCount);
}
/* nsISchemaParticle getParticle (in PRUint32 index); */
NS_IMETHODIMP
nsSchemaModelGroupRef::GetParticle(PRUint32 index, nsISchemaParticle **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
if (!mModelGroup) {
return NS_ERROR_NOT_INITIALIZED;
}
return mModelGroup->GetParticle(index, _retval);
}
////////////////////////////////////////////////////////////
//
// nsSchemaAnyParticle implementation
//
////////////////////////////////////////////////////////////
nsSchemaAnyParticle::nsSchemaAnyParticle(nsISchema* aSchema)
: nsSchemaParticleBase(aSchema), mProcess(PROCESS_STRICT)
{
NS_INIT_ISUPPORTS();
}
nsSchemaAnyParticle::~nsSchemaAnyParticle()
{
}
NS_IMPL_ISUPPORTS3(nsSchemaAnyParticle,
nsISchemaComponent,
nsISchemaParticle,
nsISchemaAnyParticle)
/* void resolve (); */
NS_IMETHODIMP
nsSchemaAnyParticle::Resolve()
{
return NS_OK;
}
/* void clear (); */
NS_IMETHODIMP
nsSchemaAnyParticle::Clear()
{
return NS_OK;
}
NS_IMETHODIMP
nsSchemaAnyParticle::GetParticleType(PRUint16 *aParticleType)
{
NS_ENSURE_ARG_POINTER(aParticleType);
*aParticleType = nsISchemaParticle::PARTICLE_TYPE_ANY;
return NS_OK;
}
NS_IMETHODIMP
nsSchemaAnyParticle::GetName(nsAWritableString& aName)
{
aName.Assign(NS_LITERAL_STRING("any"));
return NS_OK;
}
/* readonly attribute unsigned short process; */
NS_IMETHODIMP
nsSchemaAnyParticle::GetProcess(PRUint16 *aProcess)
{
NS_ENSURE_ARG_POINTER(aProcess);
*aProcess = mProcess;
return NS_OK;
}
/* readonly attribute AString namespace; */
NS_IMETHODIMP
nsSchemaAnyParticle::GetNamespace(nsAWritableString & aNamespace)
{
aNamespace.Assign(mNamespace);
return NS_OK;
}
NS_IMETHODIMP
nsSchemaAnyParticle::SetProcess(PRUint16 aProcess)
{
mProcess = aProcess;
return NS_OK;
}
NS_IMETHODIMP
nsSchemaAnyParticle::SetNamespace(const nsAReadableString& aNamespace)
{
mNamespace.Assign(aNamespace);
return NS_OK;
}
////////////////////////////////////////////////////////////
//
// nsSchemaElement implementation
//
////////////////////////////////////////////////////////////
nsSchemaElement::nsSchemaElement(nsISchema* aSchema,
const nsAReadableString& aName)
: nsSchemaParticleBase(aSchema), mName(aName),
mNillable(PR_FALSE), mAbstract(PR_FALSE)
{
NS_INIT_ISUPPORTS();
}
nsSchemaElement::~nsSchemaElement()
{
}
NS_IMPL_ISUPPORTS3(nsSchemaElement,
nsISchemaComponent,
nsISchemaParticle,
nsISchemaElement)
/* void resolve (); */
NS_IMETHODIMP
nsSchemaElement::Resolve()
{
if (mIsResolving) {
return NS_OK;
}
mIsResolving = PR_TRUE;
nsresult rv = mType->Resolve();
mIsResolving = PR_FALSE;
return rv;
}
/* void clear (); */
NS_IMETHODIMP
nsSchemaElement::Clear()
{
if (mIsClearing) {
return NS_OK;
}
mIsClearing = PR_TRUE;
mType->Clear();
mType = nsnull;
mIsClearing = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP
nsSchemaElement::GetParticleType(PRUint16 *aParticleType)
{
NS_ENSURE_ARG_POINTER(aParticleType);
*aParticleType = nsISchemaParticle::PARTICLE_TYPE_ELEMENT;
return NS_OK;
}
NS_IMETHODIMP
nsSchemaElement::GetName(nsAWritableString& aName)
{
aName.Assign(mName);
return NS_OK;
}
/* readonly attribute nsISchemaType type; */
NS_IMETHODIMP
nsSchemaElement::GetType(nsISchemaType * *aType)
{
NS_ENSURE_ARG_POINTER(aType);
*aType = mType;
NS_IF_ADDREF(*aType);
return NS_OK;
}
/* readonly attribute AString defaultValue; */
NS_IMETHODIMP
nsSchemaElement::GetDefaultValue(nsAWritableString & aDefaultValue)
{
aDefaultValue.Assign(mDefaultValue);
return NS_OK;
}
/* readonly attribute AString fixedValue; */
NS_IMETHODIMP
nsSchemaElement::GetFixedValue(nsAWritableString & aFixedValue)
{
aFixedValue.Assign(mFixedValue);
return NS_OK;
}
/* readonly attribute boolean nillable; */
NS_IMETHODIMP
nsSchemaElement::GetNillable(PRBool *aNillable)
{
NS_ENSURE_ARG_POINTER(aNillable);
*aNillable = mNillable;
return NS_OK;
}
/* readonly attribute boolean abstract; */
NS_IMETHODIMP
nsSchemaElement::GetAbstract(PRBool *aAbstract)
{
NS_ENSURE_ARG_POINTER(aAbstract);
*aAbstract = mAbstract;
return NS_OK;
}
NS_IMETHODIMP
nsSchemaElement::SetType(nsISchemaType* aType)
{
NS_ENSURE_ARG_POINTER(aType);
mType = aType;
return NS_OK;
}
NS_IMETHODIMP
nsSchemaElement::SetConstraints(const nsAReadableString& aDefaultValue,
const nsAReadableString& aFixedValue)
{
mDefaultValue.Assign(aDefaultValue);
mFixedValue.Assign(aFixedValue);
return NS_OK;
}
NS_IMETHODIMP
nsSchemaElement::SetFlags(PRBool aNillable, PRBool aAbstract)
{
mNillable = aNillable;
mAbstract = aAbstract;
return NS_OK;
}
////////////////////////////////////////////////////////////
//
// nsSchemaElementRef implementation
//
////////////////////////////////////////////////////////////
nsSchemaElementRef::nsSchemaElementRef(nsISchema* aSchema,
const nsAReadableString& aRef)
: nsSchemaParticleBase(aSchema), mRef(aRef)
{
NS_INIT_ISUPPORTS();
}
nsSchemaElementRef::~nsSchemaElementRef()
{
}
NS_IMPL_ISUPPORTS3(nsSchemaElementRef,
nsISchemaComponent,
nsISchemaParticle,
nsISchemaElement)
/* void resolve (); */
NS_IMETHODIMP
nsSchemaElementRef::Resolve()
{
nsresult rv = NS_OK;
if (mIsResolving) {
return NS_OK;
}
mIsResolving = PR_TRUE;
if (!mElement && mSchema) {
mSchema->GetElementByName(mRef, getter_AddRefs(mElement));
}
if (mElement) {
rv = mElement->Resolve();
}
mIsResolving = PR_FALSE;
return rv;
}
/* void clear (); */
NS_IMETHODIMP
nsSchemaElementRef::Clear()
{
if (mIsClearing) {
return NS_OK;
}
mIsClearing = PR_TRUE;
mElement->Clear();
mElement = nsnull;
mIsClearing = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP
nsSchemaElementRef::GetParticleType(PRUint16 *aParticleType)
{
NS_ENSURE_ARG_POINTER(aParticleType);
*aParticleType = nsISchemaParticle::PARTICLE_TYPE_ELEMENT;
return NS_OK;
}
NS_IMETHODIMP
nsSchemaElementRef::GetName(nsAWritableString& aName)
{
if (!mElement) {
return NS_ERROR_NOT_INITIALIZED;
}
return mElement->GetName(aName);
}
/* readonly attribute nsISchemaType type; */
NS_IMETHODIMP
nsSchemaElementRef::GetType(nsISchemaType * *aType)
{
NS_ENSURE_ARG_POINTER(aType);
if (!mElement) {
return NS_ERROR_NOT_INITIALIZED;
}
return mElement->GetType(aType);
}
/* readonly attribute AString defaultValue; */
NS_IMETHODIMP
nsSchemaElementRef::GetDefaultValue(nsAWritableString & aDefaultValue)
{
if (!mElement) {
return NS_ERROR_NOT_INITIALIZED;
}
return mElement->GetDefaultValue(aDefaultValue);
}
/* readonly attribute AString fixedValue; */
NS_IMETHODIMP
nsSchemaElementRef::GetFixedValue(nsAWritableString & aFixedValue)
{
if (!mElement) {
return NS_ERROR_NOT_INITIALIZED;
}
return mElement->GetFixedValue(aFixedValue);
}
/* readonly attribute boolean nillable; */
NS_IMETHODIMP
nsSchemaElementRef::GetNillable(PRBool *aNillable)
{
NS_ENSURE_ARG_POINTER(aNillable);
if (!mElement) {
return NS_ERROR_NOT_INITIALIZED;
}
return mElement->GetNillable(aNillable);
}
/* readonly attribute boolean abstract; */
NS_IMETHODIMP
nsSchemaElementRef::GetAbstract(PRBool *aAbstract)
{
NS_ENSURE_ARG_POINTER(aAbstract);
if (!mElement) {
return NS_ERROR_NOT_INITIALIZED;
}
return mElement->GetAbstract(aAbstract);
}

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

@ -0,0 +1,460 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla.
*
* The Initial Developer of the Original Code is Netscape
* Communications. Portions created by Netscape Communications are
* Copyright (C) 2001 by Netscape Communications. All
* Rights Reserved.
*
* Contributor(s):
* Vidur Apparao <vidur@netscape.com> (original author)
*/
#ifndef __nsSchemaPrivate_h__
#define __nsSchemaPrivate_h__
#include "nsISchema.h"
// XPCOM Includes
#include "nsCOMPtr.h"
#include "nsSupportsArray.h"
#include "nsHashtable.h"
#include "nsString.h"
class nsSchema : public nsISchema
{
public:
nsSchema(const nsAReadableString& aTargetNamespace);
virtual ~nsSchema();
NS_DECL_ISUPPORTS
NS_DECL_NSISCHEMACOMPONENT
NS_DECL_NSISCHEMA
NS_IMETHOD AddType(nsISchemaType* aType);
NS_IMETHOD AddAttribute(nsISchemaAttribute* aAttribute);
NS_IMETHOD AddElement(nsISchemaElement* aElement);
NS_IMETHOD AddAttributeGroup(nsISchemaAttributeGroup* aAttributeGroup);
NS_IMETHOD AddModelGroup(nsISchemaModelGroup* aModelGroup);
protected:
nsString mTargetNamespace;
nsSupportsArray mTypes;
nsSupportsHashtable mTypesHash;
nsSupportsArray mAttributes;
nsSupportsHashtable mAttributesHash;
nsSupportsArray mElements;
nsSupportsHashtable mElementsHash;
nsSupportsArray mAttributeGroups;
nsSupportsHashtable mAttributeGroupsHash;
nsSupportsArray mModelGroups;
nsSupportsHashtable mModelGroupsHash;
};
class nsSchemaComponentBase {
public:
nsSchemaComponentBase(nsISchema* aSchema);
virtual ~nsSchemaComponentBase();
NS_IMETHOD GetTargetNamespace(nsAWritableString& aTargetNamespace);
protected:
nsISchema* mSchema; // [WEAK] It owns me
// Used to prevent cyclical recursion in the object graph
PRPackedBool mIsResolving;
PRPackedBool mIsClearing;
};
#define NS_IMPL_NSISCHEMACOMPONENT_USING_BASE \
NS_IMETHOD GetTargetNamespace(nsAWritableString& aTargetNamespace) { \
return nsSchemaComponentBase::GetTargetNamespace(aTargetNamespace); \
} \
NS_IMETHOD Resolve(); \
NS_IMETHOD Clear();
class nsSchemaBuiltinType : public nsISchemaBuiltinType
{
public:
nsSchemaBuiltinType(PRUint16 aBuiltinType);
virtual ~nsSchemaBuiltinType();
NS_DECL_ISUPPORTS
NS_DECL_NSISCHEMACOMPONENT
NS_DECL_NSISCHEMATYPE
NS_DECL_NSISCHEMASIMPLETYPE
NS_DECL_NSISCHEMABUILTINTYPE
protected:
PRUint16 mBuiltinType;
};
class nsSchemaListType : public nsSchemaComponentBase,
public nsISchemaListType
{
public:
nsSchemaListType(nsISchema* aSchema, const nsAReadableString& aName);
virtual ~nsSchemaListType();
NS_DECL_ISUPPORTS
NS_IMPL_NSISCHEMACOMPONENT_USING_BASE
NS_DECL_NSISCHEMATYPE
NS_DECL_NSISCHEMASIMPLETYPE
NS_DECL_NSISCHEMALISTTYPE
NS_IMETHOD SetListType(nsISchemaSimpleType* aListType);
protected:
nsString mName;
nsCOMPtr<nsISchemaSimpleType> mListType;
};
class nsSchemaUnionType : public nsSchemaComponentBase,
public nsISchemaUnionType
{
public:
nsSchemaUnionType(nsISchema* aSchema, const nsAReadableString& aName);
virtual ~nsSchemaUnionType();
NS_DECL_ISUPPORTS
NS_IMPL_NSISCHEMACOMPONENT_USING_BASE
NS_DECL_NSISCHEMATYPE
NS_DECL_NSISCHEMASIMPLETYPE
NS_DECL_NSISCHEMAUNIONTYPE
NS_IMETHOD AddUnionType(nsISchemaSimpleType* aUnionType);
protected:
nsString mName;
nsSupportsArray mUnionTypes;
};
class nsSchemaRestrictionType : public nsSchemaComponentBase,
public nsISchemaRestrictionType
{
public:
nsSchemaRestrictionType(nsISchema* aSchema, const nsAReadableString& aName);
virtual ~nsSchemaRestrictionType();
NS_DECL_ISUPPORTS
NS_IMPL_NSISCHEMACOMPONENT_USING_BASE
NS_DECL_NSISCHEMATYPE
NS_DECL_NSISCHEMASIMPLETYPE
NS_DECL_NSISCHEMARESTRICTIONTYPE
NS_IMETHOD SetBaseType(nsISchemaSimpleType* aBaseType);
NS_IMETHOD AddFacet(nsISchemaFacet* aFacet);
protected:
nsString mName;
nsCOMPtr<nsISchemaSimpleType> mBaseType;
nsSupportsArray mFacets;
};
class nsSchemaComplexType : public nsSchemaComponentBase,
public nsISchemaComplexType
{
public:
nsSchemaComplexType(nsISchema* aSchema, const nsAReadableString& aName,
PRBool aAbstract);
virtual ~nsSchemaComplexType();
NS_DECL_ISUPPORTS
NS_IMPL_NSISCHEMACOMPONENT_USING_BASE
NS_DECL_NSISCHEMATYPE
NS_DECL_NSISCHEMACOMPLEXTYPE
NS_IMETHOD SetContentModel(PRUint16 aContentModel);
NS_IMETHOD SetDerivation(PRUint16 aDerivation, nsISchemaType* aBaseType);
NS_IMETHOD SetModelGroup(nsISchemaModelGroup* aModelGroup);
NS_IMETHOD AddAttribute(nsISchemaAttributeComponent* aAttribute);
protected:
nsString mName;
PRUint16 mContentModel;
PRUint16 mDerivation;
nsCOMPtr<nsISchemaType> mBaseType;
nsCOMPtr<nsISchemaModelGroup> mModelGroup;
nsSupportsArray mAttributes;
nsSupportsHashtable mAttributesHash;
PRPackedBool mAbstract;
};
class nsSchemaParticleBase : public nsSchemaComponentBase
{
public:
nsSchemaParticleBase(nsISchema* aSchema);
virtual ~nsSchemaParticleBase();
NS_IMETHOD GetMinOccurs(PRUint32 *aMinOccurs);
NS_IMETHOD GetMaxOccurs(PRUint32 *aMaxOccurs);
NS_IMETHOD SetMinOccurs(PRUint32 aMinOccurs);
NS_IMETHOD SetMaxOccurs(PRUint32 aMaxOccurs);
protected:
PRUint32 mMinOccurs;
PRUint32 mMaxOccurs;
};
#define NS_IMPL_NSISCHEMAPARTICLE_USING_BASE \
NS_IMETHOD GetMinOccurs(PRUint32 *aMinOccurs) { \
return nsSchemaParticleBase::GetMinOccurs(aMinOccurs); \
} \
NS_IMETHOD GetMaxOccurs(PRUint32 *aMaxOccurs) { \
return nsSchemaParticleBase::GetMaxOccurs(aMaxOccurs); \
} \
NS_IMETHOD SetMinOccurs(PRUint32 aMinOccurs) { \
return nsSchemaParticleBase::SetMinOccurs(aMinOccurs); \
} \
NS_IMETHOD SetMaxOccurs(PRUint32 aMaxOccurs) { \
return nsSchemaParticleBase::SetMaxOccurs(aMaxOccurs); \
} \
NS_IMETHOD GetParticleType(PRUint16 *aParticleType); \
NS_IMETHOD GetName(nsAWritableString& aName);
class nsSchemaModelGroup : public nsSchemaParticleBase,
public nsISchemaModelGroup
{
public:
nsSchemaModelGroup(nsISchema* aSchema,
const nsAReadableString& aName,
PRUint16 aCompositor);
virtual ~nsSchemaModelGroup();
NS_DECL_ISUPPORTS
NS_IMPL_NSISCHEMACOMPONENT_USING_BASE
NS_IMPL_NSISCHEMAPARTICLE_USING_BASE
NS_DECL_NSISCHEMAMODELGROUP
NS_IMETHOD AddParticle(nsISchemaParticle* aParticle);
protected:
nsString mName;
PRUint16 mCompositor;
nsSupportsArray mParticles;
};
class nsSchemaModelGroupRef : public nsSchemaParticleBase,
public nsISchemaModelGroup
{
public:
nsSchemaModelGroupRef(nsISchema* aSchema,
const nsAReadableString& aRef);
virtual ~nsSchemaModelGroupRef();
NS_DECL_ISUPPORTS
NS_IMPL_NSISCHEMACOMPONENT_USING_BASE
NS_IMPL_NSISCHEMAPARTICLE_USING_BASE
NS_DECL_NSISCHEMAMODELGROUP
protected:
nsString mRef;
nsCOMPtr<nsISchemaModelGroup> mModelGroup;
};
class nsSchemaAnyParticle : public nsSchemaParticleBase,
public nsISchemaAnyParticle
{
public:
nsSchemaAnyParticle(nsISchema* aSchema);
virtual ~nsSchemaAnyParticle();
NS_DECL_ISUPPORTS
NS_IMPL_NSISCHEMACOMPONENT_USING_BASE
NS_IMPL_NSISCHEMAPARTICLE_USING_BASE
NS_DECL_NSISCHEMAANYPARTICLE
NS_IMETHOD SetProcess(PRUint16 aProcess);
NS_IMETHOD SetNamespace(const nsAReadableString& aNamespace);
protected:
PRUint16 mProcess;
nsString mNamespace;
};
class nsSchemaElement : public nsSchemaParticleBase,
public nsISchemaElement
{
public:
nsSchemaElement(nsISchema* aSchema, const nsAReadableString& aName);
virtual ~nsSchemaElement();
NS_DECL_ISUPPORTS
NS_IMPL_NSISCHEMACOMPONENT_USING_BASE
NS_IMPL_NSISCHEMAPARTICLE_USING_BASE
NS_DECL_NSISCHEMAELEMENT
NS_IMETHOD SetType(nsISchemaType* aType);
NS_IMETHOD SetConstraints(const nsAReadableString& aDefaultValue,
const nsAReadableString& aFixedValue);
NS_IMETHOD SetFlags(PRBool aNillable, PRBool aAbstract);
protected:
nsString mName;
nsCOMPtr<nsISchemaType> mType;
nsString mDefaultValue;
nsString mFixedValue;
PRPackedBool mNillable;
PRPackedBool mAbstract;
};
class nsSchemaElementRef : public nsSchemaParticleBase,
public nsISchemaElement
{
public:
nsSchemaElementRef(nsISchema* aSchema, const nsAReadableString& aRef);
virtual ~nsSchemaElementRef();
NS_DECL_ISUPPORTS
NS_IMPL_NSISCHEMACOMPONENT_USING_BASE
NS_IMPL_NSISCHEMAPARTICLE_USING_BASE
NS_DECL_NSISCHEMAELEMENT
protected:
nsString mRef;
nsCOMPtr<nsISchemaElement> mElement;
};
class nsSchemaAttribute : public nsSchemaComponentBase,
public nsISchemaAttribute
{
public:
nsSchemaAttribute(nsISchema* aSchema, const nsAReadableString& aName);
virtual ~nsSchemaAttribute();
NS_DECL_ISUPPORTS
NS_IMPL_NSISCHEMACOMPONENT_USING_BASE
NS_DECL_NSISCHEMAATTRIBUTECOMPONENT
NS_DECL_NSISCHEMAATTRIBUTE
NS_IMETHOD SetType(nsISchemaSimpleType* aType);
NS_IMETHOD SetConstraints(const nsAReadableString& aDefaultValue,
const nsAReadableString& aFixedValue);
NS_IMETHOD SetUse(PRUint16 aUse);
protected:
nsString mName;
nsCOMPtr<nsISchemaSimpleType> mType;
nsString mDefaultValue;
nsString mFixedValue;
PRUint16 mUse;
};
class nsSchemaAttributeRef : public nsSchemaComponentBase,
public nsISchemaAttribute
{
public:
nsSchemaAttributeRef(nsISchema* aSchema, const nsAReadableString& aRef);
virtual ~nsSchemaAttributeRef();
NS_DECL_ISUPPORTS
NS_IMPL_NSISCHEMACOMPONENT_USING_BASE
NS_DECL_NSISCHEMAATTRIBUTECOMPONENT
NS_DECL_NSISCHEMAATTRIBUTE
NS_IMETHOD SetConstraints(const nsAReadableString& aDefaultValue,
const nsAReadableString& aFixedValue);
NS_IMETHOD SetUse(PRUint16 aUse);
protected:
nsString mRef;
nsCOMPtr<nsISchemaAttribute> mAttribute;
nsString mDefaultValue;
nsString mFixedValue;
PRUint16 mUse;
};
class nsSchemaAttributeGroup : public nsSchemaComponentBase,
public nsISchemaAttributeGroup
{
public:
nsSchemaAttributeGroup(nsISchema* aSchema, const nsAReadableString& aName);
virtual ~nsSchemaAttributeGroup();
NS_DECL_ISUPPORTS
NS_IMPL_NSISCHEMACOMPONENT_USING_BASE
NS_DECL_NSISCHEMAATTRIBUTECOMPONENT
NS_DECL_NSISCHEMAATTRIBUTEGROUP
NS_IMETHOD AddAttribute(nsISchemaAttributeComponent* aAttribute);
protected:
nsString mName;
nsSupportsArray mAttributes;
nsSupportsHashtable mAttributesHash;
};
class nsSchemaAttributeGroupRef : public nsSchemaComponentBase,
public nsISchemaAttributeGroup
{
public:
nsSchemaAttributeGroupRef(nsISchema* aSchema, const nsAReadableString& aRef);
virtual ~nsSchemaAttributeGroupRef();
NS_DECL_ISUPPORTS
NS_IMPL_NSISCHEMACOMPONENT_USING_BASE
NS_DECL_NSISCHEMAATTRIBUTECOMPONENT
NS_DECL_NSISCHEMAATTRIBUTEGROUP
protected:
nsString mRef;
nsCOMPtr<nsISchemaAttributeGroup> mAttributeGroup;
};
class nsSchemaAnyAttribute : public nsSchemaComponentBase,
public nsISchemaAnyAttribute
{
public:
nsSchemaAnyAttribute(nsISchema* aSchema);
virtual ~nsSchemaAnyAttribute();
NS_DECL_ISUPPORTS
NS_IMPL_NSISCHEMACOMPONENT_USING_BASE
NS_DECL_NSISCHEMAATTRIBUTECOMPONENT
NS_DECL_NSISCHEMAANYATTRIBUTE
NS_IMETHOD SetProcess(PRUint16 aProcess);
NS_IMETHOD SetNamespace(const nsAReadableString& aNamespace);
protected:
PRUint16 mProcess;
nsString mNamespace;
};
class nsSchemaFacet : public nsSchemaComponentBase,
public nsISchemaFacet
{
public:
nsSchemaFacet(nsISchema* aSchema, PRUint16 aFacetType, PRBool aIsFixed);
virtual ~nsSchemaFacet();
NS_DECL_ISUPPORTS
NS_IMPL_NSISCHEMACOMPONENT_USING_BASE
NS_DECL_NSISCHEMAFACET
NS_IMETHOD SetValue(const nsAReadableString& aStrValue);
NS_IMETHOD SetDigitsValue(PRUint32 aDigitsValue);
NS_IMETHOD SetWhitespaceValue(PRUint16 aWhitespaceValue);
protected:
PRUint16 mFacetType;
PRPackedBool mIsFixed;
nsString mStrValue;
PRUint32 mDigitsValue;
PRUint16 mWhitespaceValue;
};
#endif // __nsSchemaPrivate_h__

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

@ -0,0 +1,746 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla.
*
* The Initial Developer of the Original Code is Netscape
* Communications. Portions created by Netscape Communications are
* Copyright (C) 2001 by Netscape Communications. All
* Rights Reserved.
*
* Contributor(s):
* Vidur Apparao <vidur@netscape.com> (original author)
*/
#include "nsSchemaPrivate.h"
////////////////////////////////////////////////////////////
//
// nsSchemaBuiltinType implementation
//
////////////////////////////////////////////////////////////
nsSchemaBuiltinType::nsSchemaBuiltinType(PRUint16 aBuiltinType)
: mBuiltinType(aBuiltinType)
{
NS_INIT_ISUPPORTS();
}
nsSchemaBuiltinType::~nsSchemaBuiltinType()
{
}
NS_IMPL_ISUPPORTS4(nsSchemaBuiltinType,
nsISchemaComponent,
nsISchemaType,
nsISchemaSimpleType,
nsISchemaBuiltinType)
/* readonly attribute wstring targetNamespace; */
NS_IMETHODIMP
nsSchemaBuiltinType::GetTargetNamespace(nsAWritableString& aTargetNamespace)
{
aTargetNamespace.Assign(NS_LITERAL_STRING("http://www.w3.org/2001/XMLSchema"));
return NS_OK;
}
/* void resolve (); */
NS_IMETHODIMP
nsSchemaBuiltinType::Resolve()
{
return NS_OK;
}
/* void clear (); */
NS_IMETHODIMP
nsSchemaBuiltinType::Clear()
{
return NS_OK;
}
/* readonly attribute wstring name; */
NS_IMETHODIMP
nsSchemaBuiltinType::GetName(nsAWritableString& aName)
{
switch(mBuiltinType) {
case BUILTIN_TYPE_URTYPE:
aName.Assign(NS_LITERAL_STRING("anyType"));
break;
case BUILTIN_TYPE_STRING:
aName.Assign(NS_LITERAL_STRING("string"));
break;
case BUILTIN_TYPE_NORMALIZED_STRING:
aName.Assign(NS_LITERAL_STRING("normalizedString"));
break;
case BUILTIN_TYPE_TOKEN:
aName.Assign(NS_LITERAL_STRING("token"));
break;
case BUILTIN_TYPE_BYTE:
aName.Assign(NS_LITERAL_STRING("byte"));
break;
case BUILTIN_TYPE_UNSIGNEDBYTE:
aName.Assign(NS_LITERAL_STRING("unsignedByte"));
break;
case BUILTIN_TYPE_BASE64BINARY:
aName.Assign(NS_LITERAL_STRING("base64Binary"));
break;
case BUILTIN_TYPE_HEXBINARY:
aName.Assign(NS_LITERAL_STRING("hexBinary"));
break;
case BUILTIN_TYPE_INTEGER:
aName.Assign(NS_LITERAL_STRING("integer"));
break;
case BUILTIN_TYPE_POSITIVEINTEGER:
aName.Assign(NS_LITERAL_STRING("positiveInteger"));
break;
case BUILTIN_TYPE_NEGATIVEINTEGER:
aName.Assign(NS_LITERAL_STRING("negativeInteger"));
break;
case BUILTIN_TYPE_NONNEGATIVEINTEGER:
aName.Assign(NS_LITERAL_STRING("nonNegativeInteger"));
break;
case BUILTIN_TYPE_NONPOSITIVEINTEGER:
aName.Assign(NS_LITERAL_STRING("nonpositiveInteger"));
break;
case BUILTIN_TYPE_INT:
aName.Assign(NS_LITERAL_STRING("int"));
break;
case BUILTIN_TYPE_UNSIGNEDINT:
aName.Assign(NS_LITERAL_STRING("unsignedInt"));
break;
case BUILTIN_TYPE_LONG:
aName.Assign(NS_LITERAL_STRING("long"));
break;
case BUILTIN_TYPE_UNSIGNEDLONG:
aName.Assign(NS_LITERAL_STRING("unsignedLong"));
break;
case BUILTIN_TYPE_SHORT:
aName.Assign(NS_LITERAL_STRING("short"));
break;
case BUILTIN_TYPE_UNSIGNEDSHORT:
aName.Assign(NS_LITERAL_STRING("unsignedShort"));
break;
case BUILTIN_TYPE_DECIMAL:
aName.Assign(NS_LITERAL_STRING("decimal"));
break;
case BUILTIN_TYPE_FLOAT:
aName.Assign(NS_LITERAL_STRING("float"));
break;
case BUILTIN_TYPE_DOUBLE:
aName.Assign(NS_LITERAL_STRING("double"));
break;
case BUILTIN_TYPE_BOOLEAN:
aName.Assign(NS_LITERAL_STRING("boolean"));
break;
case BUILTIN_TYPE_TIME:
aName.Assign(NS_LITERAL_STRING("time"));
break;
case BUILTIN_TYPE_DATETIME:
aName.Assign(NS_LITERAL_STRING("dateTime"));
break;
case BUILTIN_TYPE_DURATION:
aName.Assign(NS_LITERAL_STRING("duration"));
break;
case BUILTIN_TYPE_DATE:
aName.Assign(NS_LITERAL_STRING("date"));
break;
case BUILTIN_TYPE_GMONTH:
aName.Assign(NS_LITERAL_STRING("gMonth"));
break;
case BUILTIN_TYPE_GYEAR:
aName.Assign(NS_LITERAL_STRING("gYear"));
break;
case BUILTIN_TYPE_GYEARMONTH:
aName.Assign(NS_LITERAL_STRING("gYearMonth"));
break;
case BUILTIN_TYPE_GDAY:
aName.Assign(NS_LITERAL_STRING("gDay"));
break;
case BUILTIN_TYPE_GMONTHDAY:
aName.Assign(NS_LITERAL_STRING("gMonthDay"));
break;
case BUILTIN_TYPE_NAME:
aName.Assign(NS_LITERAL_STRING("name"));
break;
case BUILTIN_TYPE_QNAME:
aName.Assign(NS_LITERAL_STRING("QName"));
break;
case BUILTIN_TYPE_NCNAME:
aName.Assign(NS_LITERAL_STRING("NCName"));
break;
case BUILTIN_TYPE_ANYURI:
aName.Assign(NS_LITERAL_STRING("anyURI"));
break;
case BUILTIN_TYPE_LANGUAGE:
aName.Assign(NS_LITERAL_STRING("language"));
break;
case BUILTIN_TYPE_ID:
aName.Assign(NS_LITERAL_STRING("ID"));
break;
case BUILTIN_TYPE_IDREF:
aName.Assign(NS_LITERAL_STRING("IDREF"));
break;
case BUILTIN_TYPE_IDREFS:
aName.Assign(NS_LITERAL_STRING("IDREF"));
break;
case BUILTIN_TYPE_ENTITY:
aName.Assign(NS_LITERAL_STRING("ENTITY"));
break;
case BUILTIN_TYPE_ENTITIES:
aName.Assign(NS_LITERAL_STRING("ENTITIES"));
break;
case BUILTIN_TYPE_NOTATION:
aName.Assign(NS_LITERAL_STRING("NOTATION"));
break;
case BUILTIN_TYPE_NMTOKEN:
aName.Assign(NS_LITERAL_STRING("NMTOKEN"));
break;
case BUILTIN_TYPE_NMTOKENS:
aName.Assign(NS_LITERAL_STRING("NMTOKENS"));
break;
default:
NS_ERROR("Unknown builtin type!");
aName.Truncate();
}
return NS_OK;
}
/* readonly attribute unsigned short schemaType; */
NS_IMETHODIMP
nsSchemaBuiltinType::GetSchemaType(PRUint16 *aSchemaType)
{
NS_ENSURE_ARG_POINTER(aSchemaType);
*aSchemaType = nsISchemaType::SCHEMA_TYPE_SIMPLE;
return NS_OK;
}
/* readonly attribute unsigned short simpleType; */
NS_IMETHODIMP
nsSchemaBuiltinType::GetSimpleType(PRUint16 *aSimpleType)
{
NS_ENSURE_ARG_POINTER(aSimpleType);
*aSimpleType = nsISchemaSimpleType::SIMPLE_TYPE_BUILTIN;
return NS_OK;
}
/* readonly attribute unsigned short builtinType; */
NS_IMETHODIMP
nsSchemaBuiltinType::GetBuiltinType(PRUint16 *aBuiltinType)
{
NS_ENSURE_ARG_POINTER(aBuiltinType);
*aBuiltinType = mBuiltinType;
return NS_OK;
}
////////////////////////////////////////////////////////////
//
// nsSchemaListType implementation
//
////////////////////////////////////////////////////////////
nsSchemaListType::nsSchemaListType(nsISchema* aSchema,
const nsAReadableString& aName)
: nsSchemaComponentBase(aSchema), mName(aName)
{
NS_INIT_ISUPPORTS();
}
nsSchemaListType::~nsSchemaListType()
{
}
NS_IMPL_ISUPPORTS4(nsSchemaListType,
nsISchemaComponent,
nsISchemaType,
nsISchemaSimpleType,
nsISchemaListType)
/* void resolve (); */
NS_IMETHODIMP
nsSchemaListType::Resolve()
{
return NS_OK;
}
/* void clear (); */
NS_IMETHODIMP
nsSchemaListType::Clear()
{
if (mIsClearing) {
return NS_OK;
}
mIsClearing = PR_TRUE;
if (mListType) {
mListType->Clear();
mListType = nsnull;
}
mIsClearing = PR_FALSE;
return NS_OK;
}
/* readonly attribute wstring name; */
NS_IMETHODIMP
nsSchemaListType::GetName(nsAWritableString& aName)
{
aName.Assign(mName);
return NS_OK;
}
/* readonly attribute unsigned short schemaType; */
NS_IMETHODIMP
nsSchemaListType::GetSchemaType(PRUint16 *aSchemaType)
{
NS_ENSURE_ARG_POINTER(aSchemaType);
*aSchemaType = nsISchemaType::SCHEMA_TYPE_SIMPLE;
return NS_OK;
}
/* readonly attribute unsigned short simpleType; */
NS_IMETHODIMP
nsSchemaListType::GetSimpleType(PRUint16 *aSimpleType)
{
NS_ENSURE_ARG_POINTER(aSimpleType);
*aSimpleType = nsISchemaSimpleType::SIMPLE_TYPE_LIST;
return NS_OK;
}
/* readonly attribute nsISchemaSimpleType listType; */
NS_IMETHODIMP
nsSchemaListType::GetListType(nsISchemaSimpleType * *aListType)
{
NS_ENSURE_ARG_POINTER(aListType);
*aListType = mListType;
NS_IF_ADDREF(*aListType);
return NS_OK;
}
NS_IMETHODIMP
nsSchemaListType::SetListType(nsISchemaSimpleType* aListType)
{
mListType = aListType;
return NS_OK;
}
////////////////////////////////////////////////////////////
//
// nsSchemaUnionType implementation
//
////////////////////////////////////////////////////////////
nsSchemaUnionType::nsSchemaUnionType(nsISchema* aSchema,
const nsAReadableString& aName)
: nsSchemaComponentBase(aSchema), mName(aName)
{
NS_INIT_ISUPPORTS();
}
nsSchemaUnionType::~nsSchemaUnionType()
{
}
NS_IMPL_ISUPPORTS4(nsSchemaUnionType,
nsISchemaComponent,
nsISchemaType,
nsISchemaSimpleType,
nsISchemaUnionType)
/* void resolve (); */
NS_IMETHODIMP
nsSchemaUnionType::Resolve()
{
return NS_OK;
}
/* void clear (); */
NS_IMETHODIMP
nsSchemaUnionType::Clear()
{
if (mIsClearing) {
return NS_OK;
}
mIsClearing = PR_TRUE;
nsresult rv;
PRUint32 i, count;
mUnionTypes.Count(&count);
for (i = 0; i < count; i++) {
nsCOMPtr<nsISchemaSimpleType> type;
rv = mUnionTypes.QueryElementAt(i, NS_GET_IID(nsISchemaSimpleType),
getter_AddRefs(type));
if (NS_SUCCEEDED(rv)) {
type->Clear();
}
}
mUnionTypes.Clear();
mIsClearing = PR_FALSE;
return NS_OK;
}
/* readonly attribute wstring name; */
NS_IMETHODIMP
nsSchemaUnionType::GetName(nsAWritableString& aName)
{
aName.Assign(mName);
return NS_OK;
}
/* readonly attribute unsigned short schemaType; */
NS_IMETHODIMP
nsSchemaUnionType::GetSchemaType(PRUint16 *aSchemaType)
{
NS_ENSURE_ARG_POINTER(aSchemaType);
*aSchemaType = nsISchemaType::SCHEMA_TYPE_SIMPLE;
return NS_OK;
}
/* readonly attribute unsigned short simpleType; */
NS_IMETHODIMP
nsSchemaUnionType::GetSimpleType(PRUint16 *aSimpleType)
{
NS_ENSURE_ARG_POINTER(aSimpleType);
*aSimpleType = nsISchemaSimpleType::SIMPLE_TYPE_UNION;
return NS_OK;
}
/* readonly attribute PRUint32 unionTypeCount; */
NS_IMETHODIMP
nsSchemaUnionType::GetUnionTypeCount(PRUint32 *aUnionTypeCount)
{
NS_ENSURE_ARG_POINTER(aUnionTypeCount);
return mUnionTypes.Count(aUnionTypeCount);
}
/* nsISchemaSimpleType getUnionType (in PRUint32 index); */
NS_IMETHODIMP
nsSchemaUnionType::GetUnionType(PRUint32 index, nsISchemaSimpleType **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
return mUnionTypes.QueryElementAt(index, NS_GET_IID(nsISchemaSimpleType),
(void**)_retval);
}
NS_IMETHODIMP
nsSchemaUnionType::AddUnionType(nsISchemaSimpleType* aType)
{
NS_ENSURE_ARG(aType);
return mUnionTypes.AppendElement(aType);
}
////////////////////////////////////////////////////////////
//
// nsSchemaRestrictionType implementation
//
////////////////////////////////////////////////////////////
nsSchemaRestrictionType::nsSchemaRestrictionType(nsISchema* aSchema,
const nsAReadableString& aName)
: nsSchemaComponentBase(aSchema), mName(aName)
{
NS_INIT_ISUPPORTS();
}
nsSchemaRestrictionType::~nsSchemaRestrictionType()
{
}
NS_IMPL_ISUPPORTS4(nsSchemaRestrictionType,
nsISchemaComponent,
nsISchemaType,
nsISchemaSimpleType,
nsISchemaRestrictionType)
/* void resolve (); */
NS_IMETHODIMP
nsSchemaRestrictionType::Resolve()
{
return NS_OK;
}
/* void clear (); */
NS_IMETHODIMP
nsSchemaRestrictionType::Clear()
{
if (mIsClearing) {
return NS_OK;
}
mIsClearing = PR_TRUE;
if (mBaseType) {
mBaseType->Clear();
mBaseType = nsnull;
}
nsresult rv;
PRUint32 i, count;
mFacets.Count(&count);
for (i = 0; i < count; i++) {
nsCOMPtr<nsISchemaFacet> facet;
rv = mFacets.QueryElementAt(i, NS_GET_IID(nsISchemaFacet),
getter_AddRefs(facet));
if (NS_SUCCEEDED(rv)) {
facet->Clear();
}
}
mFacets.Clear();
mIsClearing = PR_FALSE;
return NS_OK;
}
/* readonly attribute wstring name; */
NS_IMETHODIMP
nsSchemaRestrictionType::GetName(nsAWritableString& aName)
{
aName.Assign(mName);
return NS_OK;
}
/* readonly attribute unsigned short schemaType; */
NS_IMETHODIMP
nsSchemaRestrictionType::GetSchemaType(PRUint16 *aSchemaType)
{
NS_ENSURE_ARG_POINTER(aSchemaType);
*aSchemaType = nsISchemaType::SCHEMA_TYPE_SIMPLE;
return NS_OK;
}
/* readonly attribute unsigned short simpleType; */
NS_IMETHODIMP
nsSchemaRestrictionType::GetSimpleType(PRUint16 *aSimpleType)
{
NS_ENSURE_ARG_POINTER(aSimpleType);
*aSimpleType = nsISchemaSimpleType::SIMPLE_TYPE_RESTRICTION;
return NS_OK;
}
/* readonly attribute nsISchemaSimpleType baseType; */
NS_IMETHODIMP
nsSchemaRestrictionType::GetBaseType(nsISchemaSimpleType * *aBaseType)
{
NS_ENSURE_ARG_POINTER(aBaseType);
*aBaseType = mBaseType;
NS_IF_ADDREF(*aBaseType);
return NS_OK;
}
/* readonly attribute PRUint32 facetCount; */
NS_IMETHODIMP
nsSchemaRestrictionType::GetFacetCount(PRUint32 *aFacetCount)
{
NS_ENSURE_ARG_POINTER(aFacetCount);
return mFacets.Count(aFacetCount);
}
/* nsISchemaFacet getFacets (in PRUint32 index); */
NS_IMETHODIMP
nsSchemaRestrictionType::GetFacets(PRUint32 index, nsISchemaFacet **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
return mFacets.QueryElementAt(index, NS_GET_IID(nsISchemaFacet),
(void**)_retval);
}
NS_IMETHODIMP
nsSchemaRestrictionType::SetBaseType(nsISchemaSimpleType* aBaseType)
{
NS_ENSURE_ARG(aBaseType);
mBaseType = aBaseType;
return NS_OK;
}
NS_IMETHODIMP
nsSchemaRestrictionType::AddFacet(nsISchemaFacet* aFacet)
{
NS_ENSURE_ARG(aFacet);
return mFacets.AppendElement(aFacet);
}
/* End of implementation class template. */
////////////////////////////////////////////////////////////
//
// nsSchemaFacet implementation
//
////////////////////////////////////////////////////////////
nsSchemaFacet::nsSchemaFacet(nsISchema* aSchema,
PRUint16 aFacetType,
PRBool aIsFixed)
: nsSchemaComponentBase(aSchema), mFacetType(aFacetType), mIsFixed(aIsFixed)
{
NS_INIT_ISUPPORTS();
}
nsSchemaFacet::~nsSchemaFacet()
{
}
NS_IMPL_ISUPPORTS2(nsSchemaFacet,
nsISchemaComponent,
nsISchemaFacet)
/* void resolve (); */
NS_IMETHODIMP
nsSchemaFacet::Resolve()
{
return NS_OK;
}
/* void clear (); */
NS_IMETHODIMP
nsSchemaFacet::Clear()
{
return NS_OK;
}
/* readonly attribute unsigned short facetType; */
NS_IMETHODIMP
nsSchemaFacet::GetFacetType(PRUint16 *aFacetType)
{
NS_ENSURE_ARG_POINTER(aFacetType);
*aFacetType = mFacetType;
return NS_OK;
}
/* readonly attribute AString value; */
NS_IMETHODIMP
nsSchemaFacet::GetValue(nsAWritableString & aValue)
{
if ((mFacetType == FACET_TYPE_TOTALDIGITS) ||
(mFacetType == FACET_TYPE_FRACTIONDIGITS) ||
(mFacetType == FACET_TYPE_WHITESPACE)) {
return NS_ERROR_ILLEGAL_VALUE;
}
aValue.Assign(mStrValue);
return NS_OK;
}
/* readonly attribute PRUint32 digitsValue; */
NS_IMETHODIMP
nsSchemaFacet::GetDigitsValue(PRUint32 *aDigitsValue)
{
NS_ENSURE_ARG_POINTER(aDigitsValue);
if ((mFacetType != FACET_TYPE_TOTALDIGITS) &&
(mFacetType != FACET_TYPE_FRACTIONDIGITS)) {
return NS_ERROR_ILLEGAL_VALUE;
}
*aDigitsValue = mDigitsValue;
return NS_OK;
}
/* readonly attribute unsigned short whitespaceValue; */
NS_IMETHODIMP
nsSchemaFacet::GetWhitespaceValue(PRUint16 *aWhitespaceValue)
{
NS_ENSURE_ARG_POINTER(aWhitespaceValue);
if (mFacetType != FACET_TYPE_WHITESPACE) {
return NS_ERROR_ILLEGAL_VALUE;
}
*aWhitespaceValue = mWhitespaceValue;
return NS_OK;
}
/* readonly attribute boolean isfixed; */
NS_IMETHODIMP
nsSchemaFacet::GetIsfixed(PRBool *aIsFixed)
{
NS_ENSURE_ARG_POINTER(aIsFixed);
*aIsFixed = mIsFixed;
return NS_OK;
}
NS_IMETHODIMP
nsSchemaFacet::SetValue(const nsAReadableString& aStrValue)
{
if ((mFacetType == FACET_TYPE_TOTALDIGITS) ||
(mFacetType == FACET_TYPE_FRACTIONDIGITS) ||
(mFacetType == FACET_TYPE_WHITESPACE)) {
return NS_ERROR_ILLEGAL_VALUE;
}
mStrValue.Assign(aStrValue);
return NS_OK;
}
NS_IMETHODIMP
nsSchemaFacet::SetDigitsValue(PRUint32 aDigitsValue)
{
if ((mFacetType != FACET_TYPE_TOTALDIGITS) &&
(mFacetType != FACET_TYPE_FRACTIONDIGITS)) {
return NS_ERROR_ILLEGAL_VALUE;
}
mDigitsValue = aDigitsValue;
return NS_OK;
}
NS_IMETHODIMP
nsSchemaFacet::SetWhitespaceValue(PRUint16 aWhitespaceValue)
{
if (mFacetType != FACET_TYPE_WHITESPACE) {
return NS_ERROR_ILLEGAL_VALUE;
}
mWhitespaceValue = aWhitespaceValue;
return NS_OK;
}

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

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

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

@ -0,0 +1,36 @@
#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
#
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = xmlextras
XPIDLSRCS = \
.\nsISchema.idl \
.\nsISchemaLoader.idl \
$(NULL)
include $(topsrcdir)/config/rules.mk

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

@ -0,0 +1,30 @@
#!nmake
#
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
DEPTH=..\..\..\..
XPIDLSRCS = .\nsISchema.idl \
.\nsISchemaLoader.idl \
$(NULL)
MODULE=xmlextras
include <$(DEPTH)\config\rules.mak>

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

@ -0,0 +1,303 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla.
*
* The Initial Developer of the Original Code is Netscape
* Communications. Portions created by Netscape Communications are
* Copyright (C) 2001 by Netscape Communications. All
* Rights Reserved.
*
* Contributor(s):
* Vidur Apparao <vidur@netscape.com> (original author)
*/
#include "nsISupports.idl"
%{ C++
#include "nsAWritableString.h"
%}
interface nsISchemaComponent;
interface nsISchema;
interface nsISchemaType;
interface nsISchemaSimpleType;
interface nsISchemaBuiltinType;
interface nsISchemaListType;
interface nsISchemaUnionType;
interface nsISchemaRestrictionType;
interface nsISchemaComplexType;
interface nsISchemaParticle;
interface nsISchemaModelGroup;
interface nsISchemaAnyParticle;
interface nsISchemaElement;
interface nsISchemaAttributeComponent;
interface nsISchemaAttribute;
interface nsISchemaAttributeGroup;
interface nsISchemaAnyAttribute;
interface nsISchemaFacet;
[scriptable, uuid(3c14a020-6f4e-11d5-9b46-000064657374)]
interface nsISchemaComponent : nsISupports {
readonly attribute AString targetNamespace;
void resolve();
void clear();
};
[scriptable, uuid(3c14a021-6f4e-11d5-9b46-000064657374)]
interface nsISchema : nsISchemaComponent {
readonly attribute PRUint32 typeCount;
nsISchemaType getTypeByIndex(in PRUint32 index);
nsISchemaType getTypeByName(in AString name);
readonly attribute PRUint32 attributeCount;
nsISchemaAttribute getAttributeByIndex(in PRUint32 index);
nsISchemaAttribute getAttributeByName(in AString name);
readonly attribute PRUint32 elementCount;
nsISchemaElement getElementByIndex(in PRUint32 index);
nsISchemaElement getElementByName(in AString name);
readonly attribute PRUint32 attributeGroupCount;
nsISchemaAttributeGroup getAttributeGroupByIndex(in PRUint32 index);
nsISchemaAttributeGroup getAttributeGroupByName(in AString name);
readonly attribute PRUint32 modelGroupCount;
nsISchemaModelGroup getModelGroupByIndex(in PRUint32 index);
nsISchemaModelGroup getModelGroupByName(in AString name);
};
[scriptable, uuid(3c14a022-6f4e-11d5-9b46-000064657374)]
interface nsISchemaType : nsISchemaComponent {
const unsigned short SCHEMA_TYPE_SIMPLE = 1;
const unsigned short SCHEMA_TYPE_COMPLEX = 2;
readonly attribute AString name;
readonly attribute unsigned short schemaType;
};
[scriptable, uuid(3c14a023-6f4e-11d5-9b46-000064657374)]
interface nsISchemaSimpleType : nsISchemaType {
const unsigned short SIMPLE_TYPE_BUILTIN = 1;
const unsigned short SIMPLE_TYPE_LIST = 2;
const unsigned short SIMPLE_TYPE_UNION = 3;
const unsigned short SIMPLE_TYPE_RESTRICTION = 4;
readonly attribute unsigned short simpleType;
};
[scriptable, uuid(3c14a024-6f4e-11d5-9b46-000064657374)]
interface nsISchemaBuiltinType : nsISchemaSimpleType {
const unsigned short BUILTIN_TYPE_URTYPE = 1;
const unsigned short BUILTIN_TYPE_STRING = 2;
const unsigned short BUILTIN_TYPE_NORMALIZED_STRING = 3;
const unsigned short BUILTIN_TYPE_TOKEN = 4;
const unsigned short BUILTIN_TYPE_BYTE = 5;
const unsigned short BUILTIN_TYPE_UNSIGNEDBYTE = 6;
const unsigned short BUILTIN_TYPE_BASE64BINARY = 7;
const unsigned short BUILTIN_TYPE_HEXBINARY = 8;
const unsigned short BUILTIN_TYPE_INTEGER = 9;
const unsigned short BUILTIN_TYPE_POSITIVEINTEGER = 10;
const unsigned short BUILTIN_TYPE_NEGATIVEINTEGER = 11;
const unsigned short BUILTIN_TYPE_NONNEGATIVEINTEGER = 12;
const unsigned short BUILTIN_TYPE_NONPOSITIVEINTEGER = 13;
const unsigned short BUILTIN_TYPE_INT = 14;
const unsigned short BUILTIN_TYPE_UNSIGNEDINT = 15;
const unsigned short BUILTIN_TYPE_LONG = 16;
const unsigned short BUILTIN_TYPE_UNSIGNEDLONG = 17;
const unsigned short BUILTIN_TYPE_SHORT = 18;
const unsigned short BUILTIN_TYPE_UNSIGNEDSHORT = 19;
const unsigned short BUILTIN_TYPE_DECIMAL = 20;
const unsigned short BUILTIN_TYPE_FLOAT = 21;
const unsigned short BUILTIN_TYPE_DOUBLE = 22;
const unsigned short BUILTIN_TYPE_BOOLEAN = 23;
const unsigned short BUILTIN_TYPE_TIME = 24;
const unsigned short BUILTIN_TYPE_DATETIME = 25;
const unsigned short BUILTIN_TYPE_DURATION = 26;
const unsigned short BUILTIN_TYPE_DATE = 27;
const unsigned short BUILTIN_TYPE_GMONTH = 28;
const unsigned short BUILTIN_TYPE_GYEAR = 29;
const unsigned short BUILTIN_TYPE_GYEARMONTH = 30;
const unsigned short BUILTIN_TYPE_GDAY = 31;
const unsigned short BUILTIN_TYPE_GMONTHDAY = 32;
const unsigned short BUILTIN_TYPE_NAME = 33;
const unsigned short BUILTIN_TYPE_QNAME = 34;
const unsigned short BUILTIN_TYPE_NCNAME = 35;
const unsigned short BUILTIN_TYPE_ANYURI = 36;
const unsigned short BUILTIN_TYPE_LANGUAGE = 37;
const unsigned short BUILTIN_TYPE_ID = 38;
const unsigned short BUILTIN_TYPE_IDREF = 39;
const unsigned short BUILTIN_TYPE_IDREFS = 40;
const unsigned short BUILTIN_TYPE_ENTITY = 41;
const unsigned short BUILTIN_TYPE_ENTITIES = 42;
const unsigned short BUILTIN_TYPE_NOTATION = 43;
const unsigned short BUILTIN_TYPE_NMTOKEN = 44;
const unsigned short BUILTIN_TYPE_NMTOKENS = 45;
readonly attribute unsigned short builtinType;
};
[scriptable, uuid(3c14a025-6f4e-11d5-9b46-000064657374)]
interface nsISchemaListType : nsISchemaSimpleType {
readonly attribute nsISchemaSimpleType listType;
};
[scriptable, uuid(3c14a026-6f4e-11d5-9b46-000064657374)]
interface nsISchemaUnionType : nsISchemaSimpleType {
readonly attribute PRUint32 unionTypeCount;
nsISchemaSimpleType getUnionType(in PRUint32 index);
};
[scriptable, uuid(3c14a027-6f4e-11d5-9b46-000064657374)]
interface nsISchemaRestrictionType : nsISchemaSimpleType {
readonly attribute nsISchemaSimpleType baseType;
readonly attribute PRUint32 facetCount;
nsISchemaFacet getFacets(in PRUint32 index);
};
[scriptable, uuid(3c14a028-6f4e-11d5-9b46-000064657374)]
interface nsISchemaComplexType : nsISchemaType {
const unsigned short CONTENT_MODEL_EMPTY = 1;
const unsigned short CONTENT_MODEL_SIMPLE = 2;
const unsigned short CONTENT_MODEL_ELEMENT_ONLY = 3;
const unsigned short CONTENT_MODEL_MIXED = 4;
const unsigned short DERIVATION_EXTENSION_SIMPLE = 1;
const unsigned short DERIVATION_EXTENSION_COMPLEX = 2;
const unsigned short DERIVATION_RESTRICTION = 3; // Restriction of a complex type
const unsigned short DERIVATION_SELF_CONTAINED = 4; // Restriction of ur-type
readonly attribute unsigned short contentModel;
readonly attribute unsigned short derivation;
readonly attribute nsISchemaType baseType;
readonly attribute nsISchemaModelGroup modelGroup;
readonly attribute PRUint32 attributeCount;
nsISchemaAttributeComponent getAttributeByIndex(in PRUint32 index);
nsISchemaAttributeComponent getAttributeByName(in AString name);
readonly attribute boolean abstract;
};
[scriptable, uuid(3c14a029-6f4e-11d5-9b46-000064657374)]
interface nsISchemaParticle : nsISchemaComponent {
const unsigned short PARTICLE_TYPE_ELEMENT = 1;
const unsigned short PARTICLE_TYPE_MODEL_GROUP = 2;
const unsigned short PARTICLE_TYPE_ANY = 3;
readonly attribute AString name;
readonly attribute unsigned short particleType;
readonly attribute PRUint32 minOccurs;
readonly attribute PRUint32 maxOccurs;
};
[scriptable, uuid(3c14a02a-6f4e-11d5-9b46-000064657374)]
interface nsISchemaModelGroup : nsISchemaParticle {
const unsigned short COMPOSITOR_ALL = 1;
const unsigned short COMPOSITOR_SEQUENCE = 2;
const unsigned short COMPOSITOR_CHOICE = 3;
readonly attribute unsigned short compositor;
readonly attribute PRUint32 particleCount;
nsISchemaParticle getParticle(in PRUint32 index);
};
[scriptable, uuid(3c14a02b-6f4e-11d5-9b46-000064657374)]
interface nsISchemaAnyParticle : nsISchemaParticle {
const unsigned short PROCESS_STRICT = 1;
const unsigned short PROCESS_SKIP = 2;
const unsigned short PROCESS_LAX = 3;
readonly attribute unsigned short process;
readonly attribute AString namespace;
};
[scriptable, uuid(3c14a02c-6f4e-11d5-9b46-000064657374)]
interface nsISchemaElement : nsISchemaParticle {
readonly attribute nsISchemaType type;
readonly attribute AString defaultValue;
readonly attribute AString fixedValue;
readonly attribute boolean nillable;
readonly attribute boolean abstract;
};
[scriptable, uuid(3c14a02d-6f4e-11d5-9b46-000064657374)]
interface nsISchemaAttributeComponent : nsISchemaComponent {
const unsigned short COMPONENT_TYPE_ATTRIBUTE = 1;
const unsigned short COMPONENT_TYPE_GROUP = 2;
const unsigned short COMPONENT_TYPE_ANY = 3;
readonly attribute AString name;
readonly attribute unsigned short componentType;
};
[scriptable, uuid(3c14a02e-6f4e-11d5-9b46-000064657374)]
interface nsISchemaAttribute : nsISchemaAttributeComponent {
const unsigned short USE_OPTIONAL = 1;
const unsigned short USE_PROHIBITED = 2;
const unsigned short USE_REQUIRED = 3;
readonly attribute nsISchemaSimpleType type;
readonly attribute AString defaultValue;
readonly attribute AString fixedValue;
readonly attribute unsigned short use;
};
[scriptable, uuid(3c14a02f-6f4e-11d5-9b46-000064657374)]
interface nsISchemaAttributeGroup : nsISchemaAttributeComponent {
readonly attribute PRUint32 attributeCount;
nsISchemaAttributeComponent getAttributeByIndex(in PRUint32 index);
nsISchemaAttributeComponent getAttributeByName(in AString name);
};
[scriptable, uuid(3c14a030-6f4e-11d5-9b46-000064657374)]
interface nsISchemaAnyAttribute : nsISchemaAttributeComponent {
const unsigned short PROCESS_STRICT = 1;
const unsigned short PROCESS_SKIP = 2;
const unsigned short PROCESS_LAX = 3;
readonly attribute unsigned short process;
readonly attribute AString namespace;
};
[scriptable, uuid(3c14a031-6f4e-11d5-9b46-000064657374)]
interface nsISchemaFacet : nsISchemaComponent {
const unsigned short FACET_TYPE_LENGTH = 1;
const unsigned short FACET_TYPE_MINLENGTH = 2;
const unsigned short FACET_TYPE_MAXLENGTH = 3;
const unsigned short FACET_TYPE_PATTERN = 4;
const unsigned short FACET_TYPE_ENUMERATION = 5;
const unsigned short FACET_TYPE_WHITESPACE = 6;
const unsigned short FACET_TYPE_MAXINCLUSIVE = 7;
const unsigned short FACET_TYPE_MININCLUSIVE = 8;
const unsigned short FACET_TYPE_MAXEXCLUSIVE = 9;
const unsigned short FACET_TYPE_MINEXCLUSIVE = 10;
const unsigned short FACET_TYPE_TOTALDIGITS = 11;
const unsigned short FACET_TYPE_FRACTIONDIGITS = 12;
const unsigned short WHITESPACE_PRESERVE = 1;
const unsigned short WHITESPACE_REPLACE = 1;
const unsigned short WHITESPACE_COLLAPSE = 1;
readonly attribute unsigned short facetType;
readonly attribute AString value;
readonly attribute PRUint32 digitsValue; // For totalDigits and fractionDigits only
readonly attribute unsigned short whitespaceValue; // For whitespace only
readonly attribute boolean isfixed;
};

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

@ -0,0 +1,52 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla.
*
* The Initial Developer of the Original Code is Netscape
* Communications. Portions created by Netscape Communications are
* Copyright (C) 2001 by Netscape Communications. All
* Rights Reserved.
*
* Contributor(s):
* Vidur Apparao <vidur@netscape.com> (original author)
*/
#include "nsISupports.idl"
interface nsISchema;
interface nsIURI;
interface nsIDOMElement;
interface nsISchemaLoadListener;
[scriptable, uuid(3c14a032-6f4e-11d5-9b46-000064657374)]
interface nsISchemaLoader : nsISupports {
nsISchema load(in nsIURI schemaURI);
void loadAsync(in nsIURI schemaURI, in nsISchemaLoadListener listener);
nsISchema processSchemaElement(in nsIDOMElement element);
};
[scriptable, uuid(3c14a033-6f4e-11d5-9b46-000064657374)]
interface nsISchemaLoadListener : nsISupports {
void onError(in PRInt32 status,
in wstring statusMessage);
void onComplete(in nsISchema schema);
};
%{ C++
#define NS_SCHEMALOADER_CID \
{ /* 5adc10f0-74e1-11d5-9b49-00104bdf5339 */ \
0x5adc10f0, 0x74e1, 0x11d5, \
{0x9b, 0x49, 0x00, 0x10, 0x4b, 0xdf, 0x53, 0x39}}
#define NS_SCHEMALOADER_CONTRACTID "@mozilla.org/xmlextras/schemaloader;1"
%}

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

@ -0,0 +1,47 @@
#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
#
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = xmlextras
LIBRARY_NAME = xmlextrasschema_s
REQUIRES = xpcom string dom caps necko xpconnect
CPPSRCS = \
nsSchema.cpp \
nsSchemaComponentBase.cpp \
nsSchemaSimpleTypes.cpp \
nsSchemaComplexType.cpp \
nsSchemaParticles.cpp \
nsSchemaAttributes.cpp \
nsSchemaLoader.cpp \
$(NULL)
# we don't want the shared lib, but we want to force the creation of a
# static lib.
FORCE_STATIC_LIB = 1
include $(topsrcdir)/config/rules.mk

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

@ -0,0 +1,66 @@
#!nmake
#
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
DEPTH=..\..\..\..
LIBRARY_NAME=xmlextrasschema_s
MODULE=xmlextras
DEFINES=-D_IMPL_NS_HTML -DWIN32_LEAN_AND_MEAN
CPPSRCS= \
nsSchema.cpp \
nsSchemaComponentBase.cpp \
nsSchemaSimpleTypes.cpp \
nsSchemaComplexType.cpp \
nsSchemaParticles.cpp \
nsSchemaAttributes.cpp \
nsSchemaLoader.cpp \
$(NULL)
CPP_OBJS= \
.\$(OBJDIR)\nsSchema.obj \
.\$(OBJDIR)\nsSchemaComponentBase.obj \
.\$(OBJDIR)\nsSchemaSimpleTypes.obj \
.\$(OBJDIR)\nsSchemaComplexType.obj \
.\$(OBJDIR)\nsSchemaParticles.obj \
.\$(OBJDIR)\nsSchemaAttributes.obj \
.\$(OBJDIR)\nsSchemaLoader.obj \
$(NULL)
EXPORTS = \
$(NULL)
LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor -I$(PUBLIC)\js \
-I$(PUBLIC)\dom -I$(PUBLIC)\uconv
LCFLAGS = \
$(LCFLAGS) \
$(DEFINES) \
$(NULL)
include <$(DEPTH)\config\rules.mak>
install:: $(LIBRARY)
$(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib
clobber::
rm -f $(DIST)\lib\$(LIBRARY_NAME).lib

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

@ -0,0 +1,448 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla.
*
* The Initial Developer of the Original Code is Netscape
* Communications. Portions created by Netscape Communications are
* Copyright (C) 2001 by Netscape Communications. All
* Rights Reserved.
*
* Contributor(s):
* Vidur Apparao <vidur@netscape.com> (original author)
*/
#include "nsSchemaPrivate.h"
////////////////////////////////////////////////////////////
//
// nsSchema implementation
//
////////////////////////////////////////////////////////////
nsSchema::nsSchema(const nsAReadableString& aTargetNamespace)
: mTargetNamespace(aTargetNamespace)
{
NS_INIT_ISUPPORTS();
}
nsSchema::~nsSchema()
{
}
NS_IMPL_ISUPPORTS2(nsSchema, nsISchema, nsISchemaComponent)
/* readonly attribute wstring targetNamespace; */
NS_IMETHODIMP
nsSchema::GetTargetNamespace(nsAWritableString& aTargetNamespace)
{
aTargetNamespace.Assign(mTargetNamespace);
return NS_OK;
}
/* void resolve (); */
NS_IMETHODIMP
nsSchema::Resolve()
{
nsresult rv;
PRUint32 i, count;
mTypes.Count(&count);
for (i = 0; i < count; i++) {
nsCOMPtr<nsISchemaType> type;
rv = mTypes.QueryElementAt(i, NS_GET_IID(nsISchemaType),
getter_AddRefs(type));
if (NS_SUCCEEDED(rv)) {
rv = type->Resolve();
NS_ENSURE_SUCCESS(rv, rv);
}
}
mAttributes.Count(&count);
for (i = 0; i < count; i++) {
nsCOMPtr<nsISchemaAttribute> attribute;
rv = mAttributes.QueryElementAt(i, NS_GET_IID(nsISchemaAttribute),
getter_AddRefs(attribute));
if (NS_SUCCEEDED(rv)) {
rv = attribute->Resolve();
NS_ENSURE_SUCCESS(rv, rv);
}
}
mElements.Count(&count);
for (i = 0; i < count; i++) {
nsCOMPtr<nsISchemaElement> element;
rv = mElements.QueryElementAt(i, NS_GET_IID(nsISchemaElement),
getter_AddRefs(element));
if (NS_SUCCEEDED(rv)) {
rv = element->Resolve();
NS_ENSURE_SUCCESS(rv, rv);
}
}
mAttributeGroups.Count(&count);
for (i = 0; i < count; i++) {
nsCOMPtr<nsISchemaAttributeGroup> attributeGroup;
rv = mAttributeGroups.QueryElementAt(i, NS_GET_IID(nsISchemaAttributeGroup),
getter_AddRefs(attributeGroup));
if (NS_SUCCEEDED(rv)) {
rv = attributeGroup->Resolve();
NS_ENSURE_SUCCESS(rv, rv);
}
}
mModelGroups.Count(&count);
for (i = 0; i < count; i++) {
nsCOMPtr<nsISchemaModelGroup> modelGroup;
rv = mModelGroups.QueryElementAt(i, NS_GET_IID(nsISchemaModelGroup),
getter_AddRefs(modelGroup));
if (NS_SUCCEEDED(rv)) {
rv = modelGroup->Resolve();
NS_ENSURE_SUCCESS(rv, rv);
}
}
return NS_OK;
}
/* void clear (); */
NS_IMETHODIMP
nsSchema::Clear()
{
nsresult rv;
PRUint32 i, count;
mTypes.Count(&count);
for (i = 0; i < count; i++) {
nsCOMPtr<nsISchemaType> type;
rv = mTypes.QueryElementAt(i, NS_GET_IID(nsISchemaType),
getter_AddRefs(type));
if (NS_SUCCEEDED(rv)) {
type->Clear();
}
}
mTypes.Clear();
mTypesHash.Reset();
mAttributes.Count(&count);
for (i = 0; i < count; i++) {
nsCOMPtr<nsISchemaAttribute> attribute;
rv = mAttributes.QueryElementAt(i, NS_GET_IID(nsISchemaAttribute),
getter_AddRefs(attribute));
if (NS_SUCCEEDED(rv)) {
attribute->Clear();
}
}
mAttributes.Clear();
mAttributesHash.Reset();
mElements.Count(&count);
for (i = 0; i < count; i++) {
nsCOMPtr<nsISchemaElement> element;
rv = mElements.QueryElementAt(i, NS_GET_IID(nsISchemaElement),
getter_AddRefs(element));
if (NS_SUCCEEDED(rv)) {
element->Clear();
}
}
mElements.Clear();
mElementsHash.Reset();
mAttributeGroups.Count(&count);
for (i = 0; i < count; i++) {
nsCOMPtr<nsISchemaAttributeGroup> attributeGroup;
rv = mAttributeGroups.QueryElementAt(i, NS_GET_IID(nsISchemaAttributeGroup),
getter_AddRefs(attributeGroup));
if (NS_SUCCEEDED(rv)) {
attributeGroup->Clear();
}
}
mAttributeGroups.Clear();
mAttributeGroupsHash.Reset();
mModelGroups.Count(&count);
for (i = 0; i < count; i++) {
nsCOMPtr<nsISchemaModelGroup> modelGroup;
rv = mModelGroups.QueryElementAt(i, NS_GET_IID(nsISchemaModelGroup),
getter_AddRefs(modelGroup));
if (NS_SUCCEEDED(rv)) {
modelGroup->Clear();
}
}
mModelGroups.Clear();
mModelGroupsHash.Reset();
return NS_OK;
}
/* readonly attribute PRUint32 typeCount; */
NS_IMETHODIMP
nsSchema::GetTypeCount(PRUint32 *aTypeCount)
{
NS_ENSURE_ARG_POINTER(aTypeCount);
return mTypes.Count(aTypeCount);
}
/* nsISchemaType getTypeByIndex (in PRUint32 index); */
NS_IMETHODIMP
nsSchema::GetTypeByIndex(PRUint32 index, nsISchemaType **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
return mTypes.QueryElementAt(index, NS_GET_IID(nsISchemaType),
(void**)_retval);
}
/* nsISchemaType getTypeByName (in wstring name); */
NS_IMETHODIMP
nsSchema::GetTypeByName(const nsAReadableString& name, nsISchemaType **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
nsStringKey key(name);
nsCOMPtr<nsISupports> sup = dont_AddRef(mTypesHash.Get(&key));
if (sup) {
return CallQueryInterface(sup, _retval);
}
return NS_OK;
}
/* readonly attribute PRUint32 attributeCount; */
NS_IMETHODIMP
nsSchema::GetAttributeCount(PRUint32 *aAttributeCount)
{
NS_ENSURE_ARG_POINTER(aAttributeCount);
return mAttributes.Count(aAttributeCount);
}
/* nsISchemaAttribute getAttributeByIndex (in PRUint32 index); */
NS_IMETHODIMP
nsSchema::GetAttributeByIndex(PRUint32 index, nsISchemaAttribute **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
return mAttributes.QueryElementAt(index, NS_GET_IID(nsISchemaAttribute),
(void**)_retval);
}
/* nsISchemaAttribute getAttributeByName (in wstring name); */
NS_IMETHODIMP
nsSchema::GetAttributeByName(const nsAReadableString& name, nsISchemaAttribute **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
nsStringKey key(name);
nsCOMPtr<nsISupports> sup = dont_AddRef(mAttributesHash.Get(&key));
if (sup) {
return CallQueryInterface(sup, _retval);
}
return NS_OK;
}
/* readonly attribute PRUint32 elementCount; */
NS_IMETHODIMP
nsSchema::GetElementCount(PRUint32 *aElementCount)
{
NS_ENSURE_ARG_POINTER(aElementCount);
return mElements.Count(aElementCount);
}
/* nsISchemaElement getElementByIndex (in PRUint32 index); */
NS_IMETHODIMP
nsSchema::GetElementByIndex(PRUint32 index, nsISchemaElement **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
return mElements.QueryElementAt(index, NS_GET_IID(nsISchemaElement),
(void**)_retval);
}
/* nsISchemaElement getElementByName (in wstring name); */
NS_IMETHODIMP
nsSchema::GetElementByName(const nsAReadableString& name,
nsISchemaElement **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
nsStringKey key(name);
nsCOMPtr<nsISupports> sup = dont_AddRef(mElementsHash.Get(&key));
if (sup) {
return CallQueryInterface(sup, _retval);
}
return NS_OK;
}
/* readonly attribute PRUint32 attributeGroupCount; */
NS_IMETHODIMP
nsSchema::GetAttributeGroupCount(PRUint32 *aAttributeGroupCount)
{
NS_ENSURE_ARG_POINTER(aAttributeGroupCount);
return mAttributeGroups.Count(aAttributeGroupCount);
}
/* nsISchemaAttributeGroup getAttributeGroupByIndex (in PRUint32 index); */
NS_IMETHODIMP
nsSchema::GetAttributeGroupByIndex(PRUint32 index, nsISchemaAttributeGroup **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
return mAttributeGroups.QueryElementAt(index,
NS_GET_IID(nsISchemaAttributeGroup),
(void**)_retval);
}
/* nsISchemaAttributeGroup getAttributeGroupByName (in wstring name); */
NS_IMETHODIMP
nsSchema::GetAttributeGroupByName(const nsAReadableString& name, nsISchemaAttributeGroup **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
nsStringKey key(name);
nsCOMPtr<nsISupports> sup = dont_AddRef(mAttributeGroupsHash.Get(&key));
if (sup) {
return CallQueryInterface(sup, _retval);
}
return NS_OK;
}
/* readonly attribute PRUint32 modelGroupCount; */
NS_IMETHODIMP
nsSchema::GetModelGroupCount(PRUint32 *aModelGroupCount)
{
NS_ENSURE_ARG_POINTER(aModelGroupCount);
return mModelGroups.Count(aModelGroupCount);
}
/* nsISchemaModelGroup getModelGroupByIndex (in PRUint32 index); */
NS_IMETHODIMP
nsSchema::GetModelGroupByIndex(PRUint32 index, nsISchemaModelGroup **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
return mModelGroups.QueryElementAt(index,
NS_GET_IID(nsISchemaModelGroup),
(void**)_retval);
}
/* nsISchemaModelGroup getModelGroupByName (in wstring name); */
NS_IMETHODIMP
nsSchema::GetModelGroupByName(const nsAReadableString& name, nsISchemaModelGroup **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
nsStringKey key(name);
nsCOMPtr<nsISupports> sup = dont_AddRef(mModelGroupsHash.Get(&key));
if (sup) {
return CallQueryInterface(sup, _retval);
}
return NS_OK;
}
NS_IMETHODIMP
nsSchema::AddType(nsISchemaType* aType)
{
NS_ENSURE_ARG_POINTER(aType);
nsAutoString name;
aType->GetName(name);
mTypes.AppendElement(aType);
nsStringKey key(name);
mTypesHash.Put(&key, aType);
return NS_OK;
}
NS_IMETHODIMP
nsSchema::AddAttribute(nsISchemaAttribute* aAttribute)
{
NS_ENSURE_ARG_POINTER(aAttribute);
nsAutoString name;
aAttribute->GetName(name);
mAttributes.AppendElement(aAttribute);
nsStringKey key(name);
mAttributesHash.Put(&key, aAttribute);
return NS_OK;
}
NS_IMETHODIMP
nsSchema::AddElement(nsISchemaElement* aElement)
{
NS_ENSURE_ARG_POINTER(aElement);
nsAutoString name;
aElement->GetName(name);
mElements.AppendElement(aElement);
nsStringKey key(name);
mElementsHash.Put(&key, aElement);
return NS_OK;
}
NS_IMETHODIMP
nsSchema::AddAttributeGroup(nsISchemaAttributeGroup* aAttributeGroup)
{
NS_ENSURE_ARG_POINTER(aAttributeGroup);
nsAutoString name;
aAttributeGroup->GetName(name);
mAttributeGroups.AppendElement(aAttributeGroup);
nsStringKey key(name);
mAttributeGroupsHash.Put(&key, aAttributeGroup);
return NS_OK;
}
NS_IMETHODIMP
nsSchema::AddModelGroup(nsISchemaModelGroup* aModelGroup)
{
NS_ENSURE_ARG_POINTER(aModelGroup);
nsAutoString name;
aModelGroup->GetName(name);
mModelGroups.AppendElement(aModelGroup);
nsStringKey key(name);
mModelGroupsHash.Put(&key, aModelGroup);
return NS_OK;
}

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

@ -0,0 +1,665 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla.
*
* The Initial Developer of the Original Code is Netscape
* Communications. Portions created by Netscape Communications are
* Copyright (C) 2001 by Netscape Communications. All
* Rights Reserved.
*
* Contributor(s):
* Vidur Apparao <vidur@netscape.com> (original author)
*/
#include "nsSchemaPrivate.h"
////////////////////////////////////////////////////////////
//
// nsSchemaAttribute implementation
//
////////////////////////////////////////////////////////////
nsSchemaAttribute::nsSchemaAttribute(nsISchema* aSchema,
const nsAReadableString& aName)
: nsSchemaComponentBase(aSchema), mName(aName)
{
NS_INIT_ISUPPORTS();
}
nsSchemaAttribute::~nsSchemaAttribute()
{
}
NS_IMPL_ISUPPORTS3(nsSchemaAttribute,
nsISchemaComponent,
nsISchemaAttributeComponent,
nsISchemaAttribute)
/* void resolve (); */
NS_IMETHODIMP
nsSchemaAttribute::Resolve()
{
return NS_OK;
}
/* void clear (); */
NS_IMETHODIMP
nsSchemaAttribute::Clear()
{
if (mIsClearing) {
return NS_OK;
}
mIsClearing = PR_TRUE;
mType->Clear();
mType = nsnull;
mIsClearing = PR_FALSE;
return NS_OK;
}
/* readonly attribute AString name; */
NS_IMETHODIMP
nsSchemaAttribute::GetName(nsAWritableString & aName)
{
aName.Assign(mName);
return NS_OK;
}
/* readonly attribute unsigned short componentType; */
NS_IMETHODIMP
nsSchemaAttribute::GetComponentType(PRUint16 *aComponentType)
{
NS_ENSURE_ARG_POINTER(aComponentType);
*aComponentType = nsISchemaAttributeComponent::COMPONENT_TYPE_ATTRIBUTE;
return NS_OK;
}
/* readonly attribute nsISchemaSimpleType type; */
NS_IMETHODIMP
nsSchemaAttribute::GetType(nsISchemaSimpleType * *aType)
{
NS_ENSURE_ARG_POINTER(aType);
*aType = mType;
NS_IF_ADDREF(*aType);
return NS_OK;
}
/* readonly attribute AString defaultValue; */
NS_IMETHODIMP
nsSchemaAttribute::GetDefaultValue(nsAWritableString & aDefaultValue)
{
aDefaultValue.Assign(mDefaultValue);
return NS_OK;
}
/* readonly attribute AString fixedValue; */
NS_IMETHODIMP
nsSchemaAttribute::GetFixedValue(nsAWritableString & aFixedValue)
{
aFixedValue.Assign(mFixedValue);
return NS_OK;
}
/* readonly attribute unsigned short use; */
NS_IMETHODIMP
nsSchemaAttribute::GetUse(PRUint16 *aUse)
{
NS_ENSURE_ARG_POINTER(aUse);
*aUse = mUse;
return NS_OK;
}
NS_IMETHODIMP
nsSchemaAttribute::SetType(nsISchemaSimpleType* aType)
{
NS_ENSURE_ARG(aType);
mType = aType;
return NS_OK;
}
NS_IMETHODIMP
nsSchemaAttribute::SetConstraints(const nsAReadableString& aDefaultValue,
const nsAReadableString& aFixedValue)
{
mDefaultValue.Assign(aDefaultValue);
mFixedValue.Assign(aFixedValue);
return NS_OK;
}
NS_IMETHODIMP
nsSchemaAttribute::SetUse(PRUint16 aUse)
{
mUse = aUse;
return NS_OK;
}
////////////////////////////////////////////////////////////
//
// nsSchemaAttributeRef implementation
//
////////////////////////////////////////////////////////////
nsSchemaAttributeRef::nsSchemaAttributeRef(nsISchema* aSchema,
const nsAReadableString& aRef)
: nsSchemaComponentBase(aSchema), mRef(aRef)
{
NS_INIT_ISUPPORTS();
}
nsSchemaAttributeRef::~nsSchemaAttributeRef()
{
}
NS_IMPL_ISUPPORTS3(nsSchemaAttributeRef,
nsISchemaComponent,
nsISchemaAttributeComponent,
nsISchemaAttribute)
/* void resolve (); */
NS_IMETHODIMP
nsSchemaAttributeRef::Resolve()
{
nsresult rv = NS_OK;
if (mIsResolving) {
return NS_OK;
}
mIsResolving = PR_TRUE;
if (!mAttribute && mSchema) {
mSchema->GetAttributeByName(mRef, getter_AddRefs(mAttribute));
}
if (mAttribute) {
rv = mAttribute->Resolve();
}
mIsResolving = PR_FALSE;
return rv;
}
/* void clear (); */
NS_IMETHODIMP
nsSchemaAttributeRef::Clear()
{
if (mIsClearing) {
return NS_OK;
}
mIsClearing = PR_TRUE;
mAttribute->Clear();
mAttribute = nsnull;
mIsClearing = PR_FALSE;
return NS_OK;
}
/* readonly attribute AString name; */
NS_IMETHODIMP
nsSchemaAttributeRef::GetName(nsAWritableString & aName)
{
if (!mAttribute) {
return NS_ERROR_NOT_INITIALIZED;
}
return mAttribute->GetName(aName);
}
/* readonly attribute unsigned short componentType; */
NS_IMETHODIMP
nsSchemaAttributeRef::GetComponentType(PRUint16 *aComponentType)
{
NS_ENSURE_ARG_POINTER(aComponentType);
*aComponentType = nsISchemaAttributeComponent::COMPONENT_TYPE_ATTRIBUTE;
return NS_OK;
}
/* readonly attribute nsISchemaSimpleType type; */
NS_IMETHODIMP
nsSchemaAttributeRef::GetType(nsISchemaSimpleType * *aType)
{
NS_ENSURE_ARG_POINTER(aType);
if (!mAttribute) {
return NS_ERROR_NOT_INITIALIZED;
}
return mAttribute->GetType(aType);
}
/* readonly attribute AString defaultValue; */
NS_IMETHODIMP
nsSchemaAttributeRef::GetDefaultValue(nsAWritableString & aDefaultValue)
{
aDefaultValue.Assign(mDefaultValue);
return NS_OK;
}
/* readonly attribute AString fixedValue; */
NS_IMETHODIMP
nsSchemaAttributeRef::GetFixedValue(nsAWritableString & aFixedValue)
{
aFixedValue.Assign(mFixedValue);
return NS_OK;
}
/* readonly attribute unsigned short use; */
NS_IMETHODIMP
nsSchemaAttributeRef::GetUse(PRUint16 *aUse)
{
NS_ENSURE_ARG_POINTER(aUse);
*aUse = mUse;
return NS_OK;
}
NS_IMETHODIMP
nsSchemaAttributeRef::SetConstraints(const nsAReadableString& aDefaultValue,
const nsAReadableString& aFixedValue)
{
mDefaultValue.Assign(aDefaultValue);
mFixedValue.Assign(aFixedValue);
return NS_OK;
}
NS_IMETHODIMP
nsSchemaAttributeRef::SetUse(PRUint16 aUse)
{
mUse = aUse;
return NS_OK;
}
////////////////////////////////////////////////////////////
//
// nsSchemaAttributeGroup implementation
//
////////////////////////////////////////////////////////////
nsSchemaAttributeGroup::nsSchemaAttributeGroup(nsISchema* aSchema,
const nsAReadableString& aName)
: nsSchemaComponentBase(aSchema), mName(aName)
{
NS_INIT_ISUPPORTS();
}
nsSchemaAttributeGroup::~nsSchemaAttributeGroup()
{
}
NS_IMPL_ISUPPORTS3(nsSchemaAttributeGroup,
nsISchemaComponent,
nsISchemaAttributeComponent,
nsISchemaAttributeGroup)
/* void resolve (); */
NS_IMETHODIMP
nsSchemaAttributeGroup::Resolve()
{
if (mIsResolving) {
return NS_OK;
}
mIsResolving = PR_TRUE;
nsresult rv;
PRUint32 i, count;
mAttributes.Count(&count);
for (i = 0; i < count; i++) {
nsCOMPtr<nsISchemaAttributeComponent> attribute;
rv = mAttributes.QueryElementAt(i, NS_GET_IID(nsISchemaAttributeComponent),
getter_AddRefs(attribute));
if (NS_SUCCEEDED(rv)) {
rv = attribute->Resolve();
if (NS_FAILED(rv)) {
mIsResolving = PR_FALSE;
return rv;
}
}
}
mIsResolving = PR_FALSE;
return NS_OK;
}
/* void clear (); */
NS_IMETHODIMP
nsSchemaAttributeGroup::Clear()
{
if (mIsClearing) {
return NS_OK;
}
mIsClearing = PR_TRUE;
nsresult rv;
PRUint32 i, count;
mAttributes.Count(&count);
for (i = 0; i < count; i++) {
nsCOMPtr<nsISchemaAttributeComponent> attribute;
rv = mAttributes.QueryElementAt(i, NS_GET_IID(nsISchemaAttributeComponent),
getter_AddRefs(attribute));
if (NS_SUCCEEDED(rv)) {
attribute->Clear();
}
}
mAttributes.Clear();
mAttributesHash.Reset();
mIsClearing = PR_FALSE;
return NS_OK;
}
/* readonly attribute AString name; */
NS_IMETHODIMP
nsSchemaAttributeGroup::GetName(nsAWritableString & aName)
{
aName.Assign(mName);
return NS_OK;
}
/* readonly attribute unsigned short componentType; */
NS_IMETHODIMP
nsSchemaAttributeGroup::GetComponentType(PRUint16 *aComponentType)
{
NS_ENSURE_ARG_POINTER(aComponentType);
*aComponentType = nsISchemaAttributeComponent::COMPONENT_TYPE_GROUP;
return NS_OK;
}
/* readonly attribute PRUint32 attributeCount; */
NS_IMETHODIMP
nsSchemaAttributeGroup::GetAttributeCount(PRUint32 *aAttributeCount)
{
NS_ENSURE_ARG_POINTER(aAttributeCount);
return mAttributes.Count(aAttributeCount);
}
/* nsISchemaAttributeComponent getAttributeByIndex (in PRUint32 index); */
NS_IMETHODIMP
nsSchemaAttributeGroup::GetAttributeByIndex(PRUint32 index,
nsISchemaAttributeComponent **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
return mAttributes.QueryElementAt(index,
NS_GET_IID(nsISchemaAttributeComponent),
(void**)_retval);
}
/* nsISchemaAttributeComponent getAttributeByName (in AString name); */
NS_IMETHODIMP
nsSchemaAttributeGroup::GetAttributeByName(const nsAReadableString & name,
nsISchemaAttributeComponent **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
nsStringKey key(name);
nsCOMPtr<nsISupports> sup = dont_AddRef(mAttributesHash.Get(&key));
if (sup) {
return CallQueryInterface(sup, _retval);
}
return NS_OK;
}
NS_IMETHODIMP
nsSchemaAttributeGroup::AddAttribute(nsISchemaAttributeComponent* aAttribute)
{
NS_ENSURE_ARG_POINTER(aAttribute);
nsAutoString name;
aAttribute->GetName(name);
mAttributes.AppendElement(aAttribute);
nsStringKey key(name);
mAttributesHash.Put(&key, aAttribute);
return NS_OK;
}
////////////////////////////////////////////////////////////
//
// nsSchemaAttributeGroupRef implementation
//
////////////////////////////////////////////////////////////
nsSchemaAttributeGroupRef::nsSchemaAttributeGroupRef(nsISchema* aSchema,
const nsAReadableString& aRef)
: nsSchemaComponentBase(aSchema), mRef(aRef)
{
NS_INIT_ISUPPORTS();
}
nsSchemaAttributeGroupRef::~nsSchemaAttributeGroupRef()
{
}
NS_IMPL_ISUPPORTS3(nsSchemaAttributeGroupRef,
nsISchemaComponent,
nsISchemaAttributeComponent,
nsISchemaAttributeGroup)
/* void resolve (); */
NS_IMETHODIMP
nsSchemaAttributeGroupRef::Resolve()
{
nsresult rv = NS_OK;
if (mIsResolving) {
return NS_OK;
}
mIsResolving = PR_TRUE;
if (!mAttributeGroup && mSchema) {
mSchema->GetAttributeGroupByName(mRef, getter_AddRefs(mAttributeGroup));
}
if (mAttributeGroup) {
rv = mAttributeGroup->Resolve();
}
mIsResolving = PR_FALSE;
return rv;
}
/* void clear (); */
NS_IMETHODIMP
nsSchemaAttributeGroupRef::Clear()
{
if (mIsClearing) {
return NS_OK;
}
mIsClearing = PR_TRUE;
mAttributeGroup->Clear();
mAttributeGroup = nsnull;
mIsClearing = PR_FALSE;
return NS_OK;
}
/* readonly attribute AString name; */
NS_IMETHODIMP
nsSchemaAttributeGroupRef::GetName(nsAWritableString & aName)
{
if (!mAttributeGroup) {
return NS_ERROR_NOT_INITIALIZED;
}
return mAttributeGroup->GetName(aName);
}
/* readonly attribute unsigned short componentType; */
NS_IMETHODIMP
nsSchemaAttributeGroupRef::GetComponentType(PRUint16 *aComponentType)
{
NS_ENSURE_ARG_POINTER(aComponentType);
*aComponentType = nsISchemaAttributeComponent::COMPONENT_TYPE_GROUP;
return NS_OK;
}
/* readonly attribute PRUint32 attributeCount; */
NS_IMETHODIMP
nsSchemaAttributeGroupRef::GetAttributeCount(PRUint32 *aAttributeCount)
{
NS_ENSURE_ARG_POINTER(aAttributeCount);
if (!mAttributeGroup) {
return NS_ERROR_NOT_INITIALIZED;
}
return mAttributeGroup->GetAttributeCount(aAttributeCount);
}
/* nsISchemaAttributeComponent getAttributeByIndex (in PRUint32 index); */
NS_IMETHODIMP
nsSchemaAttributeGroupRef::GetAttributeByIndex(PRUint32 index,
nsISchemaAttributeComponent **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
if (!mAttributeGroup) {
return NS_ERROR_NOT_INITIALIZED;
}
return mAttributeGroup->GetAttributeByIndex(index, _retval);
}
/* nsISchemaAttributeComponent getAttributeByName (in AString name); */
NS_IMETHODIMP
nsSchemaAttributeGroupRef::GetAttributeByName(const nsAReadableString & name,
nsISchemaAttributeComponent **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
if (!mAttributeGroup) {
return NS_ERROR_NOT_INITIALIZED;
}
return mAttributeGroup->GetAttributeByName(name, _retval);
}
////////////////////////////////////////////////////////////
//
// nsSchemaAnyAttribute implementation
//
////////////////////////////////////////////////////////////
nsSchemaAnyAttribute::nsSchemaAnyAttribute(nsISchema* aSchema)
: nsSchemaComponentBase(aSchema), mProcess(PROCESS_STRICT)
{
NS_INIT_ISUPPORTS();
}
nsSchemaAnyAttribute::~nsSchemaAnyAttribute()
{
}
NS_IMPL_ISUPPORTS3(nsSchemaAnyAttribute,
nsISchemaComponent,
nsISchemaAttributeComponent,
nsISchemaAnyAttribute)
/* void resolve (); */
NS_IMETHODIMP
nsSchemaAnyAttribute::Resolve()
{
return NS_OK;
}
/* void clear (); */
NS_IMETHODIMP
nsSchemaAnyAttribute::Clear()
{
return NS_OK;
}
/* readonly attribute unsigned short componentType; */
NS_IMETHODIMP
nsSchemaAnyAttribute::GetComponentType(PRUint16 *aComponentType)
{
NS_ENSURE_ARG_POINTER(aComponentType);
*aComponentType = nsISchemaAttributeComponent::COMPONENT_TYPE_ANY;
return NS_OK;
}
/* readonly attribute AString name; */
NS_IMETHODIMP
nsSchemaAnyAttribute::GetName(nsAWritableString & aName)
{
aName.Assign(NS_LITERAL_STRING("anyAttribute"));
return NS_OK;
}
/* readonly attribute unsigned short process; */
NS_IMETHODIMP
nsSchemaAnyAttribute::GetProcess(PRUint16 *aProcess)
{
NS_ENSURE_ARG_POINTER(aProcess);
*aProcess = mProcess;
return NS_OK;
}
/* readonly attribute AString namespace; */
NS_IMETHODIMP
nsSchemaAnyAttribute::GetNamespace(nsAWritableString & aNamespace)
{
aNamespace.Assign(mNamespace);
return NS_OK;
}
NS_IMETHODIMP
nsSchemaAnyAttribute::SetProcess(PRUint16 aProcess)
{
mProcess = aProcess;
return NS_OK;
}
NS_IMETHODIMP
nsSchemaAnyAttribute::SetNamespace(const nsAReadableString& aNamespace)
{
mNamespace.Assign(aNamespace);
return NS_OK;
}

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

@ -0,0 +1,273 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla.
*
* The Initial Developer of the Original Code is Netscape
* Communications. Portions created by Netscape Communications are
* Copyright (C) 2001 by Netscape Communications. All
* Rights Reserved.
*
* Contributor(s):
* Vidur Apparao <vidur@netscape.com> (original author)
*/
#include "nsSchemaPrivate.h"
////////////////////////////////////////////////////////////
//
// nsSchemaComplexType implementation
//
////////////////////////////////////////////////////////////
nsSchemaComplexType::nsSchemaComplexType(nsISchema* aSchema,
const nsAReadableString& aName,
PRBool aAbstract)
: nsSchemaComponentBase(aSchema), mName(aName), mAbstract(aAbstract),
mContentModel(CONTENT_MODEL_ELEMENT_ONLY),
mDerivation(DERIVATION_SELF_CONTAINED)
{
NS_INIT_ISUPPORTS();
}
nsSchemaComplexType::~nsSchemaComplexType()
{
}
NS_IMPL_ISUPPORTS3(nsSchemaComplexType,
nsISchemaComponent,
nsISchemaType,
nsISchemaComplexType)
/* void resolve (); */
NS_IMETHODIMP
nsSchemaComplexType::Resolve()
{
if (mIsResolving) {
return NS_OK;
}
mIsResolving = PR_TRUE;
nsresult rv;
PRUint32 i, count;
mAttributes.Count(&count);
for (i = 0; i < count; i++) {
nsCOMPtr<nsISchemaAttributeComponent> attribute;
rv = mAttributes.QueryElementAt(i, NS_GET_IID(nsISchemaAttributeComponent),
getter_AddRefs(attribute));
if (NS_SUCCEEDED(rv)) {
rv = attribute->Resolve();
if (NS_FAILED(rv)) {
mIsResolving = PR_FALSE;
return rv;
}
}
}
mIsResolving = PR_FALSE;
return NS_OK;
}
/* void clear (); */
NS_IMETHODIMP
nsSchemaComplexType::Clear()
{
if (mIsClearing) {
return NS_OK;
}
mIsClearing = PR_TRUE;
if (mBaseType) {
mBaseType->Clear();
mBaseType = nsnull;
}
if (mModelGroup) {
mModelGroup->Clear();
mModelGroup = nsnull;
}
nsresult rv;
PRUint32 i, count;
mAttributes.Count(&count);
for (i = 0; i < count; i++) {
nsCOMPtr<nsISchemaAttributeComponent> attribute;
rv = mAttributes.QueryElementAt(i, NS_GET_IID(nsISchemaAttributeComponent),
getter_AddRefs(attribute));
if (NS_SUCCEEDED(rv)) {
attribute->Clear();
}
}
mAttributes.Clear();
mAttributesHash.Reset();
mIsClearing = PR_FALSE;
return NS_OK;
}
/* readonly attribute wstring name; */
NS_IMETHODIMP
nsSchemaComplexType::GetName(nsAWritableString& aName)
{
aName.Assign(mName);
return NS_OK;
}
/* readonly attribute unsigned short schemaType; */
NS_IMETHODIMP
nsSchemaComplexType::GetSchemaType(PRUint16 *aSchemaType)
{
NS_ENSURE_ARG_POINTER(aSchemaType);
*aSchemaType = nsISchemaType::SCHEMA_TYPE_COMPLEX;
return NS_OK;
}
/* readonly attribute unsigned short contentModel; */
NS_IMETHODIMP
nsSchemaComplexType::GetContentModel(PRUint16 *aContentModel)
{
NS_ENSURE_ARG_POINTER(aContentModel);
*aContentModel = mContentModel;
return NS_OK;
}
/* readonly attribute unsigned short derivation; */
NS_IMETHODIMP
nsSchemaComplexType::GetDerivation(PRUint16 *aDerivation)
{
NS_ENSURE_ARG_POINTER(aDerivation);
*aDerivation = mDerivation;
return NS_OK;
}
/* readonly attribute nsISchemaType baseType; */
NS_IMETHODIMP
nsSchemaComplexType::GetBaseType(nsISchemaType * *aBaseType)
{
NS_ENSURE_ARG_POINTER(aBaseType);
*aBaseType = mBaseType;
NS_IF_ADDREF(*aBaseType);
return NS_OK;
}
/* readonly attribute nsISchemaModelGroup modelGroup; */
NS_IMETHODIMP
nsSchemaComplexType::GetModelGroup(nsISchemaModelGroup * *aModelGroup)
{
NS_ENSURE_ARG_POINTER(aModelGroup);
*aModelGroup = mModelGroup;
NS_IF_ADDREF(*aModelGroup);
return NS_OK;
}
/* readonly attribute PRUint32 attributeCount; */
NS_IMETHODIMP
nsSchemaComplexType::GetAttributeCount(PRUint32 *aAttributeCount)
{
NS_ENSURE_ARG_POINTER(aAttributeCount);
return mAttributes.Count(aAttributeCount);
}
/* nsISchemaAttributeComponent getAttributeByIndex (in PRUint32 index); */
NS_IMETHODIMP
nsSchemaComplexType::GetAttributeByIndex(PRUint32 index,
nsISchemaAttributeComponent **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
return mAttributes.QueryElementAt(index,
NS_GET_IID(nsISchemaAttributeComponent),
(void**)_retval);
}
/* nsISchemaAttributeComponent getAttributeByName (in AString name); */
NS_IMETHODIMP
nsSchemaComplexType::GetAttributeByName(const nsAReadableString& name,
nsISchemaAttributeComponent **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
nsStringKey key(name);
nsCOMPtr<nsISupports> sup = dont_AddRef(mAttributesHash.Get(&key));
if (sup) {
return CallQueryInterface(sup, _retval);
}
return NS_OK;
}
/* readonly attribute boolean abstract; */
NS_IMETHODIMP
nsSchemaComplexType::GetAbstract(PRBool *aAbstract)
{
NS_ENSURE_ARG_POINTER(aAbstract);
*aAbstract = mAbstract;
return NS_OK;
}
NS_IMETHODIMP
nsSchemaComplexType::SetContentModel(PRUint16 aContentModel)
{
mContentModel = aContentModel;
return NS_OK;
}
NS_IMETHODIMP
nsSchemaComplexType::SetDerivation(PRUint16 aDerivation,
nsISchemaType* aBaseType)
{
mDerivation = aDerivation;
mBaseType = aBaseType;
return NS_OK;
}
NS_IMETHODIMP
nsSchemaComplexType::SetModelGroup(nsISchemaModelGroup* aModelGroup)
{
mModelGroup = aModelGroup;
return NS_OK;
}
NS_IMETHODIMP
nsSchemaComplexType::AddAttribute(nsISchemaAttributeComponent* aAttribute)
{
NS_ENSURE_ARG_POINTER(aAttribute);
nsAutoString name;
aAttribute->GetName(name);
mAttributes.AppendElement(aAttribute);
nsStringKey key(name);
mAttributesHash.Put(&key, aAttribute);
return NS_OK;
}

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

@ -0,0 +1,51 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla.
*
* The Initial Developer of the Original Code is Netscape
* Communications. Portions created by Netscape Communications are
* Copyright (C) 2001 by Netscape Communications. All
* Rights Reserved.
*
* Contributor(s):
* Vidur Apparao <vidur@netscape.com> (original author)
*/
#include "nsSchemaPrivate.h"
////////////////////////////////////////////////////////////
//
// nsSchemaComponentBase implementation
//
////////////////////////////////////////////////////////////
nsSchemaComponentBase::nsSchemaComponentBase(nsISchema* aSchema)
: mSchema(aSchema), mIsResolving(PR_FALSE), mIsClearing(PR_FALSE)
{
}
nsSchemaComponentBase::~nsSchemaComponentBase()
{
mSchema = nsnull;
}
/* readonly attribute wstring targetNamespace; */
NS_IMETHODIMP
nsSchemaComponentBase::GetTargetNamespace(nsAWritableString& aTargetNamespace)
{
if (mSchema) {
return mSchema->GetTargetNamespace(aTargetNamespace);
}
aTargetNamespace.Truncate();
return NS_OK;
}

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

@ -0,0 +1,78 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla.
*
* The Initial Developer of the Original Code is Netscape
* Communications. Portions created by Netscape Communications are
* Copyright (C) 2001 by Netscape Communications. All
* Rights Reserved.
*
* Contributor(s):
* Vidur Apparao <vidur@netscape.com> (original author)
*/
#include "nsSchemaPrivate.h"
#include "nsSchemaLoader.h"
nsSchemaLoader::nsSchemaLoader()
{
NS_INIT_ISUPPORTS();
}
nsSchemaLoader::~nsSchemaLoader()
{
}
NS_IMPL_ISUPPORTS1(nsSchemaLoader, nsISchemaLoader)
/* nsISchema load (in nsIURI schemaURI); */
NS_IMETHODIMP
nsSchemaLoader::Load(nsIURI *schemaURI, nsISchema **_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void loadAsync (in nsIURI schemaURI, in nsISchemaLoadListener listener); */
NS_IMETHODIMP
nsSchemaLoader::LoadAsync(nsIURI *schemaURI, nsISchemaLoadListener *listener)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* nsISchema processSchemaElement (in nsIDOMElement element); */
NS_IMETHODIMP
nsSchemaLoader::ProcessSchemaElement(nsIDOMElement *element,
nsISchema **_retval)
{
nsAutoString dummy;
nsSchema* schema = new nsSchema(dummy);
nsSchemaBuiltinType* bt = new nsSchemaBuiltinType(1);
nsSchemaListType* lt = new nsSchemaListType(schema, dummy);
nsSchemaUnionType* ut = new nsSchemaUnionType(schema, dummy);
nsSchemaRestrictionType* rt = new nsSchemaRestrictionType(schema, dummy);
nsSchemaComplexType* ct = new nsSchemaComplexType(schema, dummy, PR_FALSE);
nsSchemaModelGroup* mg = new nsSchemaModelGroup(schema, dummy, 1);
nsSchemaModelGroupRef* mgr = new nsSchemaModelGroupRef(schema, dummy);
nsSchemaAnyParticle* ap = new nsSchemaAnyParticle(schema);
nsSchemaElement* el = new nsSchemaElement(schema, dummy);
nsSchemaElementRef* elr = new nsSchemaElementRef(schema, dummy);
nsSchemaAttribute* att = new nsSchemaAttribute(schema, dummy);
nsSchemaAttributeRef* attr = new nsSchemaAttributeRef(schema, dummy);
nsSchemaAttributeGroup* attg = new nsSchemaAttributeGroup(schema, dummy);
nsSchemaAttributeGroupRef* attgr = new nsSchemaAttributeGroupRef(schema, dummy);
nsSchemaAnyAttribute* ant = new nsSchemaAnyAttribute(schema);
nsSchemaFacet* fac = new nsSchemaFacet(schema, 1, PR_FALSE);
return NS_OK;
}

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

@ -0,0 +1,40 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla.
*
* The Initial Developer of the Original Code is Netscape
* Communications. Portions created by Netscape Communications are
* Copyright (C) 2001 by Netscape Communications. All
* Rights Reserved.
*
* Contributor(s):
* Vidur Apparao <vidur@netscape.com> (original author)
*/
#ifndef __nsSchemaLoader_h__
#define __nsSchemaLoader_h__
#include "nsISchemaLoader.h"
class nsSchemaLoader : public nsISchemaLoader
{
public:
nsSchemaLoader();
virtual ~nsSchemaLoader();
NS_DECL_ISUPPORTS
NS_DECL_NSISCHEMALOADER
};
#endif // __nsSchemaLoader_h__

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

@ -0,0 +1,723 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla.
*
* The Initial Developer of the Original Code is Netscape
* Communications. Portions created by Netscape Communications are
* Copyright (C) 2001 by Netscape Communications. All
* Rights Reserved.
*
* Contributor(s):
* Vidur Apparao <vidur@netscape.com> (original author)
*/
#include "nsSchemaPrivate.h"
////////////////////////////////////////////////////////////
//
// nsSchemaParticleBase implementation
//
////////////////////////////////////////////////////////////
nsSchemaParticleBase::nsSchemaParticleBase(nsISchema* aSchema)
: nsSchemaComponentBase(aSchema), mMinOccurs(1), mMaxOccurs(1)
{
}
nsSchemaParticleBase::~nsSchemaParticleBase()
{
}
NS_IMETHODIMP
nsSchemaParticleBase::GetMinOccurs(PRUint32 *aMinOccurs)
{
NS_ENSURE_ARG_POINTER(aMinOccurs);
*aMinOccurs = mMinOccurs;
return NS_OK;
}
NS_IMETHODIMP
nsSchemaParticleBase::GetMaxOccurs(PRUint32 *aMaxOccurs)
{
NS_ENSURE_ARG_POINTER(aMaxOccurs);
*aMaxOccurs = mMaxOccurs;
return NS_OK;
}
NS_IMETHODIMP
nsSchemaParticleBase::SetMinOccurs(PRUint32 aMinOccurs)
{
mMinOccurs = aMinOccurs;
if (mMaxOccurs < mMinOccurs) {
mMaxOccurs = mMinOccurs;
}
return NS_OK;
}
NS_IMETHODIMP
nsSchemaParticleBase::SetMaxOccurs(PRUint32 aMaxOccurs)
{
mMaxOccurs = aMaxOccurs;
if (mMinOccurs > mMaxOccurs) {
mMinOccurs = mMaxOccurs;
}
return NS_OK;
}
////////////////////////////////////////////////////////////
//
// nsSchemaModelGroup implementation
//
////////////////////////////////////////////////////////////
nsSchemaModelGroup::nsSchemaModelGroup(nsISchema* aSchema,
const nsAReadableString& aName,
PRUint16 aCompositor)
: nsSchemaParticleBase(aSchema), mName(aName), mCompositor(aCompositor)
{
NS_INIT_ISUPPORTS();
}
nsSchemaModelGroup::~nsSchemaModelGroup()
{
}
NS_IMPL_ISUPPORTS3(nsSchemaModelGroup,
nsISchemaComponent,
nsISchemaParticle,
nsISchemaModelGroup)
/* void resolve (); */
NS_IMETHODIMP
nsSchemaModelGroup::Resolve()
{
if (mIsResolving) {
return NS_OK;
}
mIsResolving = PR_TRUE;
nsresult rv;
PRUint32 i, count;
mParticles.Count(&count);
for (i = 0; i < count; i++) {
nsCOMPtr<nsISchemaParticle> particle;
rv = mParticles.QueryElementAt(i, NS_GET_IID(nsISchemaParticle),
getter_AddRefs(particle));
if (NS_SUCCEEDED(rv)) {
rv = particle->Resolve();
if (NS_FAILED(rv)) {
mIsResolving = PR_FALSE;
return rv;
}
}
}
mIsResolving = PR_FALSE;
return NS_OK;
}
/* void clear (); */
NS_IMETHODIMP
nsSchemaModelGroup::Clear()
{
if (mIsClearing) {
return NS_OK;
}
mIsClearing = PR_TRUE;
nsresult rv;
PRUint32 i, count;
mParticles.Count(&count);
for (i = 0; i < count; i++) {
nsCOMPtr<nsISchemaParticle> particle;
rv = mParticles.QueryElementAt(i, NS_GET_IID(nsISchemaParticle),
getter_AddRefs(particle));
if (NS_SUCCEEDED(rv)) {
particle->Clear();
}
}
mIsClearing = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP
nsSchemaModelGroup::GetParticleType(PRUint16 *aParticleType)
{
NS_ENSURE_ARG_POINTER(aParticleType);
*aParticleType = nsISchemaParticle::PARTICLE_TYPE_MODEL_GROUP;
return NS_OK;
}
NS_IMETHODIMP
nsSchemaModelGroup::GetName(nsAWritableString& aName)
{
aName.Assign(mName);
return NS_OK;
}
/* readonly attribute unsigned short compositor; */
NS_IMETHODIMP
nsSchemaModelGroup::GetCompositor(PRUint16 *aCompositor)
{
NS_ENSURE_ARG_POINTER(aCompositor);
*aCompositor = mCompositor;
return NS_OK;
}
/* readonly attribute PRUint32 particleCount; */
NS_IMETHODIMP
nsSchemaModelGroup::GetParticleCount(PRUint32 *aParticleCount)
{
NS_ENSURE_ARG_POINTER(aParticleCount);
return mParticles.Count(aParticleCount);
}
/* nsISchemaParticle getParticle (in PRUint32 index); */
NS_IMETHODIMP
nsSchemaModelGroup::GetParticle(PRUint32 index, nsISchemaParticle **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
return mParticles.QueryElementAt(index, NS_GET_IID(nsISchemaParticle),
(void**)_retval);
}
NS_IMETHODIMP
nsSchemaModelGroup::AddParticle(nsISchemaParticle* aParticle)
{
NS_ENSURE_ARG_POINTER(aParticle);
return mParticles.AppendElement(aParticle);
}
////////////////////////////////////////////////////////////
//
// nsSchemaModelGroupRef implementation
//
////////////////////////////////////////////////////////////
nsSchemaModelGroupRef::nsSchemaModelGroupRef(nsISchema* aSchema,
const nsAReadableString& aRef)
: nsSchemaParticleBase(aSchema), mRef(aRef)
{
NS_INIT_ISUPPORTS();
}
nsSchemaModelGroupRef::~nsSchemaModelGroupRef()
{
}
NS_IMPL_ISUPPORTS3(nsSchemaModelGroupRef,
nsISchemaComponent,
nsISchemaParticle,
nsISchemaModelGroup)
/* void resolve (); */
NS_IMETHODIMP
nsSchemaModelGroupRef::Resolve()
{
nsresult rv = NS_OK;
if (mIsResolving) {
return NS_OK;
}
mIsResolving = PR_TRUE;
if (!mModelGroup && mSchema) {
mSchema->GetModelGroupByName(mRef, getter_AddRefs(mModelGroup));
}
if (mModelGroup) {
rv = mModelGroup->Resolve();
}
mIsResolving = PR_FALSE;
return rv;
}
/* void clear (); */
NS_IMETHODIMP
nsSchemaModelGroupRef::Clear()
{
if (mIsClearing) {
return NS_OK;
}
mIsClearing = PR_TRUE;
if (mModelGroup) {
mModelGroup->Clear();
mModelGroup = nsnull;
}
mIsClearing = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP
nsSchemaModelGroupRef::GetParticleType(PRUint16 *aParticleType)
{
NS_ENSURE_ARG_POINTER(aParticleType);
*aParticleType = nsISchemaParticle::PARTICLE_TYPE_MODEL_GROUP;
return NS_OK;
}
NS_IMETHODIMP
nsSchemaModelGroupRef::GetName(nsAWritableString& aName)
{
if (!mModelGroup) {
return NS_ERROR_NOT_INITIALIZED;
}
return mModelGroup->GetName(aName);
}
/* readonly attribute unsigned short compositor; */
NS_IMETHODIMP
nsSchemaModelGroupRef::GetCompositor(PRUint16 *aCompositor)
{
NS_ENSURE_ARG_POINTER(aCompositor);
if (!mModelGroup) {
return NS_ERROR_NOT_INITIALIZED;
}
return mModelGroup->GetCompositor(aCompositor);
}
/* readonly attribute PRUint32 particleCount; */
NS_IMETHODIMP
nsSchemaModelGroupRef::GetParticleCount(PRUint32 *aParticleCount)
{
NS_ENSURE_ARG_POINTER(aParticleCount);
if (!mModelGroup) {
return NS_ERROR_NOT_INITIALIZED;
}
return mModelGroup->GetParticleCount(aParticleCount);
}
/* nsISchemaParticle getParticle (in PRUint32 index); */
NS_IMETHODIMP
nsSchemaModelGroupRef::GetParticle(PRUint32 index, nsISchemaParticle **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
if (!mModelGroup) {
return NS_ERROR_NOT_INITIALIZED;
}
return mModelGroup->GetParticle(index, _retval);
}
////////////////////////////////////////////////////////////
//
// nsSchemaAnyParticle implementation
//
////////////////////////////////////////////////////////////
nsSchemaAnyParticle::nsSchemaAnyParticle(nsISchema* aSchema)
: nsSchemaParticleBase(aSchema), mProcess(PROCESS_STRICT)
{
NS_INIT_ISUPPORTS();
}
nsSchemaAnyParticle::~nsSchemaAnyParticle()
{
}
NS_IMPL_ISUPPORTS3(nsSchemaAnyParticle,
nsISchemaComponent,
nsISchemaParticle,
nsISchemaAnyParticle)
/* void resolve (); */
NS_IMETHODIMP
nsSchemaAnyParticle::Resolve()
{
return NS_OK;
}
/* void clear (); */
NS_IMETHODIMP
nsSchemaAnyParticle::Clear()
{
return NS_OK;
}
NS_IMETHODIMP
nsSchemaAnyParticle::GetParticleType(PRUint16 *aParticleType)
{
NS_ENSURE_ARG_POINTER(aParticleType);
*aParticleType = nsISchemaParticle::PARTICLE_TYPE_ANY;
return NS_OK;
}
NS_IMETHODIMP
nsSchemaAnyParticle::GetName(nsAWritableString& aName)
{
aName.Assign(NS_LITERAL_STRING("any"));
return NS_OK;
}
/* readonly attribute unsigned short process; */
NS_IMETHODIMP
nsSchemaAnyParticle::GetProcess(PRUint16 *aProcess)
{
NS_ENSURE_ARG_POINTER(aProcess);
*aProcess = mProcess;
return NS_OK;
}
/* readonly attribute AString namespace; */
NS_IMETHODIMP
nsSchemaAnyParticle::GetNamespace(nsAWritableString & aNamespace)
{
aNamespace.Assign(mNamespace);
return NS_OK;
}
NS_IMETHODIMP
nsSchemaAnyParticle::SetProcess(PRUint16 aProcess)
{
mProcess = aProcess;
return NS_OK;
}
NS_IMETHODIMP
nsSchemaAnyParticle::SetNamespace(const nsAReadableString& aNamespace)
{
mNamespace.Assign(aNamespace);
return NS_OK;
}
////////////////////////////////////////////////////////////
//
// nsSchemaElement implementation
//
////////////////////////////////////////////////////////////
nsSchemaElement::nsSchemaElement(nsISchema* aSchema,
const nsAReadableString& aName)
: nsSchemaParticleBase(aSchema), mName(aName),
mNillable(PR_FALSE), mAbstract(PR_FALSE)
{
NS_INIT_ISUPPORTS();
}
nsSchemaElement::~nsSchemaElement()
{
}
NS_IMPL_ISUPPORTS3(nsSchemaElement,
nsISchemaComponent,
nsISchemaParticle,
nsISchemaElement)
/* void resolve (); */
NS_IMETHODIMP
nsSchemaElement::Resolve()
{
if (mIsResolving) {
return NS_OK;
}
mIsResolving = PR_TRUE;
nsresult rv = mType->Resolve();
mIsResolving = PR_FALSE;
return rv;
}
/* void clear (); */
NS_IMETHODIMP
nsSchemaElement::Clear()
{
if (mIsClearing) {
return NS_OK;
}
mIsClearing = PR_TRUE;
mType->Clear();
mType = nsnull;
mIsClearing = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP
nsSchemaElement::GetParticleType(PRUint16 *aParticleType)
{
NS_ENSURE_ARG_POINTER(aParticleType);
*aParticleType = nsISchemaParticle::PARTICLE_TYPE_ELEMENT;
return NS_OK;
}
NS_IMETHODIMP
nsSchemaElement::GetName(nsAWritableString& aName)
{
aName.Assign(mName);
return NS_OK;
}
/* readonly attribute nsISchemaType type; */
NS_IMETHODIMP
nsSchemaElement::GetType(nsISchemaType * *aType)
{
NS_ENSURE_ARG_POINTER(aType);
*aType = mType;
NS_IF_ADDREF(*aType);
return NS_OK;
}
/* readonly attribute AString defaultValue; */
NS_IMETHODIMP
nsSchemaElement::GetDefaultValue(nsAWritableString & aDefaultValue)
{
aDefaultValue.Assign(mDefaultValue);
return NS_OK;
}
/* readonly attribute AString fixedValue; */
NS_IMETHODIMP
nsSchemaElement::GetFixedValue(nsAWritableString & aFixedValue)
{
aFixedValue.Assign(mFixedValue);
return NS_OK;
}
/* readonly attribute boolean nillable; */
NS_IMETHODIMP
nsSchemaElement::GetNillable(PRBool *aNillable)
{
NS_ENSURE_ARG_POINTER(aNillable);
*aNillable = mNillable;
return NS_OK;
}
/* readonly attribute boolean abstract; */
NS_IMETHODIMP
nsSchemaElement::GetAbstract(PRBool *aAbstract)
{
NS_ENSURE_ARG_POINTER(aAbstract);
*aAbstract = mAbstract;
return NS_OK;
}
NS_IMETHODIMP
nsSchemaElement::SetType(nsISchemaType* aType)
{
NS_ENSURE_ARG_POINTER(aType);
mType = aType;
return NS_OK;
}
NS_IMETHODIMP
nsSchemaElement::SetConstraints(const nsAReadableString& aDefaultValue,
const nsAReadableString& aFixedValue)
{
mDefaultValue.Assign(aDefaultValue);
mFixedValue.Assign(aFixedValue);
return NS_OK;
}
NS_IMETHODIMP
nsSchemaElement::SetFlags(PRBool aNillable, PRBool aAbstract)
{
mNillable = aNillable;
mAbstract = aAbstract;
return NS_OK;
}
////////////////////////////////////////////////////////////
//
// nsSchemaElementRef implementation
//
////////////////////////////////////////////////////////////
nsSchemaElementRef::nsSchemaElementRef(nsISchema* aSchema,
const nsAReadableString& aRef)
: nsSchemaParticleBase(aSchema), mRef(aRef)
{
NS_INIT_ISUPPORTS();
}
nsSchemaElementRef::~nsSchemaElementRef()
{
}
NS_IMPL_ISUPPORTS3(nsSchemaElementRef,
nsISchemaComponent,
nsISchemaParticle,
nsISchemaElement)
/* void resolve (); */
NS_IMETHODIMP
nsSchemaElementRef::Resolve()
{
nsresult rv = NS_OK;
if (mIsResolving) {
return NS_OK;
}
mIsResolving = PR_TRUE;
if (!mElement && mSchema) {
mSchema->GetElementByName(mRef, getter_AddRefs(mElement));
}
if (mElement) {
rv = mElement->Resolve();
}
mIsResolving = PR_FALSE;
return rv;
}
/* void clear (); */
NS_IMETHODIMP
nsSchemaElementRef::Clear()
{
if (mIsClearing) {
return NS_OK;
}
mIsClearing = PR_TRUE;
mElement->Clear();
mElement = nsnull;
mIsClearing = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP
nsSchemaElementRef::GetParticleType(PRUint16 *aParticleType)
{
NS_ENSURE_ARG_POINTER(aParticleType);
*aParticleType = nsISchemaParticle::PARTICLE_TYPE_ELEMENT;
return NS_OK;
}
NS_IMETHODIMP
nsSchemaElementRef::GetName(nsAWritableString& aName)
{
if (!mElement) {
return NS_ERROR_NOT_INITIALIZED;
}
return mElement->GetName(aName);
}
/* readonly attribute nsISchemaType type; */
NS_IMETHODIMP
nsSchemaElementRef::GetType(nsISchemaType * *aType)
{
NS_ENSURE_ARG_POINTER(aType);
if (!mElement) {
return NS_ERROR_NOT_INITIALIZED;
}
return mElement->GetType(aType);
}
/* readonly attribute AString defaultValue; */
NS_IMETHODIMP
nsSchemaElementRef::GetDefaultValue(nsAWritableString & aDefaultValue)
{
if (!mElement) {
return NS_ERROR_NOT_INITIALIZED;
}
return mElement->GetDefaultValue(aDefaultValue);
}
/* readonly attribute AString fixedValue; */
NS_IMETHODIMP
nsSchemaElementRef::GetFixedValue(nsAWritableString & aFixedValue)
{
if (!mElement) {
return NS_ERROR_NOT_INITIALIZED;
}
return mElement->GetFixedValue(aFixedValue);
}
/* readonly attribute boolean nillable; */
NS_IMETHODIMP
nsSchemaElementRef::GetNillable(PRBool *aNillable)
{
NS_ENSURE_ARG_POINTER(aNillable);
if (!mElement) {
return NS_ERROR_NOT_INITIALIZED;
}
return mElement->GetNillable(aNillable);
}
/* readonly attribute boolean abstract; */
NS_IMETHODIMP
nsSchemaElementRef::GetAbstract(PRBool *aAbstract)
{
NS_ENSURE_ARG_POINTER(aAbstract);
if (!mElement) {
return NS_ERROR_NOT_INITIALIZED;
}
return mElement->GetAbstract(aAbstract);
}

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

@ -0,0 +1,460 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla.
*
* The Initial Developer of the Original Code is Netscape
* Communications. Portions created by Netscape Communications are
* Copyright (C) 2001 by Netscape Communications. All
* Rights Reserved.
*
* Contributor(s):
* Vidur Apparao <vidur@netscape.com> (original author)
*/
#ifndef __nsSchemaPrivate_h__
#define __nsSchemaPrivate_h__
#include "nsISchema.h"
// XPCOM Includes
#include "nsCOMPtr.h"
#include "nsSupportsArray.h"
#include "nsHashtable.h"
#include "nsString.h"
class nsSchema : public nsISchema
{
public:
nsSchema(const nsAReadableString& aTargetNamespace);
virtual ~nsSchema();
NS_DECL_ISUPPORTS
NS_DECL_NSISCHEMACOMPONENT
NS_DECL_NSISCHEMA
NS_IMETHOD AddType(nsISchemaType* aType);
NS_IMETHOD AddAttribute(nsISchemaAttribute* aAttribute);
NS_IMETHOD AddElement(nsISchemaElement* aElement);
NS_IMETHOD AddAttributeGroup(nsISchemaAttributeGroup* aAttributeGroup);
NS_IMETHOD AddModelGroup(nsISchemaModelGroup* aModelGroup);
protected:
nsString mTargetNamespace;
nsSupportsArray mTypes;
nsSupportsHashtable mTypesHash;
nsSupportsArray mAttributes;
nsSupportsHashtable mAttributesHash;
nsSupportsArray mElements;
nsSupportsHashtable mElementsHash;
nsSupportsArray mAttributeGroups;
nsSupportsHashtable mAttributeGroupsHash;
nsSupportsArray mModelGroups;
nsSupportsHashtable mModelGroupsHash;
};
class nsSchemaComponentBase {
public:
nsSchemaComponentBase(nsISchema* aSchema);
virtual ~nsSchemaComponentBase();
NS_IMETHOD GetTargetNamespace(nsAWritableString& aTargetNamespace);
protected:
nsISchema* mSchema; // [WEAK] It owns me
// Used to prevent cyclical recursion in the object graph
PRPackedBool mIsResolving;
PRPackedBool mIsClearing;
};
#define NS_IMPL_NSISCHEMACOMPONENT_USING_BASE \
NS_IMETHOD GetTargetNamespace(nsAWritableString& aTargetNamespace) { \
return nsSchemaComponentBase::GetTargetNamespace(aTargetNamespace); \
} \
NS_IMETHOD Resolve(); \
NS_IMETHOD Clear();
class nsSchemaBuiltinType : public nsISchemaBuiltinType
{
public:
nsSchemaBuiltinType(PRUint16 aBuiltinType);
virtual ~nsSchemaBuiltinType();
NS_DECL_ISUPPORTS
NS_DECL_NSISCHEMACOMPONENT
NS_DECL_NSISCHEMATYPE
NS_DECL_NSISCHEMASIMPLETYPE
NS_DECL_NSISCHEMABUILTINTYPE
protected:
PRUint16 mBuiltinType;
};
class nsSchemaListType : public nsSchemaComponentBase,
public nsISchemaListType
{
public:
nsSchemaListType(nsISchema* aSchema, const nsAReadableString& aName);
virtual ~nsSchemaListType();
NS_DECL_ISUPPORTS
NS_IMPL_NSISCHEMACOMPONENT_USING_BASE
NS_DECL_NSISCHEMATYPE
NS_DECL_NSISCHEMASIMPLETYPE
NS_DECL_NSISCHEMALISTTYPE
NS_IMETHOD SetListType(nsISchemaSimpleType* aListType);
protected:
nsString mName;
nsCOMPtr<nsISchemaSimpleType> mListType;
};
class nsSchemaUnionType : public nsSchemaComponentBase,
public nsISchemaUnionType
{
public:
nsSchemaUnionType(nsISchema* aSchema, const nsAReadableString& aName);
virtual ~nsSchemaUnionType();
NS_DECL_ISUPPORTS
NS_IMPL_NSISCHEMACOMPONENT_USING_BASE
NS_DECL_NSISCHEMATYPE
NS_DECL_NSISCHEMASIMPLETYPE
NS_DECL_NSISCHEMAUNIONTYPE
NS_IMETHOD AddUnionType(nsISchemaSimpleType* aUnionType);
protected:
nsString mName;
nsSupportsArray mUnionTypes;
};
class nsSchemaRestrictionType : public nsSchemaComponentBase,
public nsISchemaRestrictionType
{
public:
nsSchemaRestrictionType(nsISchema* aSchema, const nsAReadableString& aName);
virtual ~nsSchemaRestrictionType();
NS_DECL_ISUPPORTS
NS_IMPL_NSISCHEMACOMPONENT_USING_BASE
NS_DECL_NSISCHEMATYPE
NS_DECL_NSISCHEMASIMPLETYPE
NS_DECL_NSISCHEMARESTRICTIONTYPE
NS_IMETHOD SetBaseType(nsISchemaSimpleType* aBaseType);
NS_IMETHOD AddFacet(nsISchemaFacet* aFacet);
protected:
nsString mName;
nsCOMPtr<nsISchemaSimpleType> mBaseType;
nsSupportsArray mFacets;
};
class nsSchemaComplexType : public nsSchemaComponentBase,
public nsISchemaComplexType
{
public:
nsSchemaComplexType(nsISchema* aSchema, const nsAReadableString& aName,
PRBool aAbstract);
virtual ~nsSchemaComplexType();
NS_DECL_ISUPPORTS
NS_IMPL_NSISCHEMACOMPONENT_USING_BASE
NS_DECL_NSISCHEMATYPE
NS_DECL_NSISCHEMACOMPLEXTYPE
NS_IMETHOD SetContentModel(PRUint16 aContentModel);
NS_IMETHOD SetDerivation(PRUint16 aDerivation, nsISchemaType* aBaseType);
NS_IMETHOD SetModelGroup(nsISchemaModelGroup* aModelGroup);
NS_IMETHOD AddAttribute(nsISchemaAttributeComponent* aAttribute);
protected:
nsString mName;
PRUint16 mContentModel;
PRUint16 mDerivation;
nsCOMPtr<nsISchemaType> mBaseType;
nsCOMPtr<nsISchemaModelGroup> mModelGroup;
nsSupportsArray mAttributes;
nsSupportsHashtable mAttributesHash;
PRPackedBool mAbstract;
};
class nsSchemaParticleBase : public nsSchemaComponentBase
{
public:
nsSchemaParticleBase(nsISchema* aSchema);
virtual ~nsSchemaParticleBase();
NS_IMETHOD GetMinOccurs(PRUint32 *aMinOccurs);
NS_IMETHOD GetMaxOccurs(PRUint32 *aMaxOccurs);
NS_IMETHOD SetMinOccurs(PRUint32 aMinOccurs);
NS_IMETHOD SetMaxOccurs(PRUint32 aMaxOccurs);
protected:
PRUint32 mMinOccurs;
PRUint32 mMaxOccurs;
};
#define NS_IMPL_NSISCHEMAPARTICLE_USING_BASE \
NS_IMETHOD GetMinOccurs(PRUint32 *aMinOccurs) { \
return nsSchemaParticleBase::GetMinOccurs(aMinOccurs); \
} \
NS_IMETHOD GetMaxOccurs(PRUint32 *aMaxOccurs) { \
return nsSchemaParticleBase::GetMaxOccurs(aMaxOccurs); \
} \
NS_IMETHOD SetMinOccurs(PRUint32 aMinOccurs) { \
return nsSchemaParticleBase::SetMinOccurs(aMinOccurs); \
} \
NS_IMETHOD SetMaxOccurs(PRUint32 aMaxOccurs) { \
return nsSchemaParticleBase::SetMaxOccurs(aMaxOccurs); \
} \
NS_IMETHOD GetParticleType(PRUint16 *aParticleType); \
NS_IMETHOD GetName(nsAWritableString& aName);
class nsSchemaModelGroup : public nsSchemaParticleBase,
public nsISchemaModelGroup
{
public:
nsSchemaModelGroup(nsISchema* aSchema,
const nsAReadableString& aName,
PRUint16 aCompositor);
virtual ~nsSchemaModelGroup();
NS_DECL_ISUPPORTS
NS_IMPL_NSISCHEMACOMPONENT_USING_BASE
NS_IMPL_NSISCHEMAPARTICLE_USING_BASE
NS_DECL_NSISCHEMAMODELGROUP
NS_IMETHOD AddParticle(nsISchemaParticle* aParticle);
protected:
nsString mName;
PRUint16 mCompositor;
nsSupportsArray mParticles;
};
class nsSchemaModelGroupRef : public nsSchemaParticleBase,
public nsISchemaModelGroup
{
public:
nsSchemaModelGroupRef(nsISchema* aSchema,
const nsAReadableString& aRef);
virtual ~nsSchemaModelGroupRef();
NS_DECL_ISUPPORTS
NS_IMPL_NSISCHEMACOMPONENT_USING_BASE
NS_IMPL_NSISCHEMAPARTICLE_USING_BASE
NS_DECL_NSISCHEMAMODELGROUP
protected:
nsString mRef;
nsCOMPtr<nsISchemaModelGroup> mModelGroup;
};
class nsSchemaAnyParticle : public nsSchemaParticleBase,
public nsISchemaAnyParticle
{
public:
nsSchemaAnyParticle(nsISchema* aSchema);
virtual ~nsSchemaAnyParticle();
NS_DECL_ISUPPORTS
NS_IMPL_NSISCHEMACOMPONENT_USING_BASE
NS_IMPL_NSISCHEMAPARTICLE_USING_BASE
NS_DECL_NSISCHEMAANYPARTICLE
NS_IMETHOD SetProcess(PRUint16 aProcess);
NS_IMETHOD SetNamespace(const nsAReadableString& aNamespace);
protected:
PRUint16 mProcess;
nsString mNamespace;
};
class nsSchemaElement : public nsSchemaParticleBase,
public nsISchemaElement
{
public:
nsSchemaElement(nsISchema* aSchema, const nsAReadableString& aName);
virtual ~nsSchemaElement();
NS_DECL_ISUPPORTS
NS_IMPL_NSISCHEMACOMPONENT_USING_BASE
NS_IMPL_NSISCHEMAPARTICLE_USING_BASE
NS_DECL_NSISCHEMAELEMENT
NS_IMETHOD SetType(nsISchemaType* aType);
NS_IMETHOD SetConstraints(const nsAReadableString& aDefaultValue,
const nsAReadableString& aFixedValue);
NS_IMETHOD SetFlags(PRBool aNillable, PRBool aAbstract);
protected:
nsString mName;
nsCOMPtr<nsISchemaType> mType;
nsString mDefaultValue;
nsString mFixedValue;
PRPackedBool mNillable;
PRPackedBool mAbstract;
};
class nsSchemaElementRef : public nsSchemaParticleBase,
public nsISchemaElement
{
public:
nsSchemaElementRef(nsISchema* aSchema, const nsAReadableString& aRef);
virtual ~nsSchemaElementRef();
NS_DECL_ISUPPORTS
NS_IMPL_NSISCHEMACOMPONENT_USING_BASE
NS_IMPL_NSISCHEMAPARTICLE_USING_BASE
NS_DECL_NSISCHEMAELEMENT
protected:
nsString mRef;
nsCOMPtr<nsISchemaElement> mElement;
};
class nsSchemaAttribute : public nsSchemaComponentBase,
public nsISchemaAttribute
{
public:
nsSchemaAttribute(nsISchema* aSchema, const nsAReadableString& aName);
virtual ~nsSchemaAttribute();
NS_DECL_ISUPPORTS
NS_IMPL_NSISCHEMACOMPONENT_USING_BASE
NS_DECL_NSISCHEMAATTRIBUTECOMPONENT
NS_DECL_NSISCHEMAATTRIBUTE
NS_IMETHOD SetType(nsISchemaSimpleType* aType);
NS_IMETHOD SetConstraints(const nsAReadableString& aDefaultValue,
const nsAReadableString& aFixedValue);
NS_IMETHOD SetUse(PRUint16 aUse);
protected:
nsString mName;
nsCOMPtr<nsISchemaSimpleType> mType;
nsString mDefaultValue;
nsString mFixedValue;
PRUint16 mUse;
};
class nsSchemaAttributeRef : public nsSchemaComponentBase,
public nsISchemaAttribute
{
public:
nsSchemaAttributeRef(nsISchema* aSchema, const nsAReadableString& aRef);
virtual ~nsSchemaAttributeRef();
NS_DECL_ISUPPORTS
NS_IMPL_NSISCHEMACOMPONENT_USING_BASE
NS_DECL_NSISCHEMAATTRIBUTECOMPONENT
NS_DECL_NSISCHEMAATTRIBUTE
NS_IMETHOD SetConstraints(const nsAReadableString& aDefaultValue,
const nsAReadableString& aFixedValue);
NS_IMETHOD SetUse(PRUint16 aUse);
protected:
nsString mRef;
nsCOMPtr<nsISchemaAttribute> mAttribute;
nsString mDefaultValue;
nsString mFixedValue;
PRUint16 mUse;
};
class nsSchemaAttributeGroup : public nsSchemaComponentBase,
public nsISchemaAttributeGroup
{
public:
nsSchemaAttributeGroup(nsISchema* aSchema, const nsAReadableString& aName);
virtual ~nsSchemaAttributeGroup();
NS_DECL_ISUPPORTS
NS_IMPL_NSISCHEMACOMPONENT_USING_BASE
NS_DECL_NSISCHEMAATTRIBUTECOMPONENT
NS_DECL_NSISCHEMAATTRIBUTEGROUP
NS_IMETHOD AddAttribute(nsISchemaAttributeComponent* aAttribute);
protected:
nsString mName;
nsSupportsArray mAttributes;
nsSupportsHashtable mAttributesHash;
};
class nsSchemaAttributeGroupRef : public nsSchemaComponentBase,
public nsISchemaAttributeGroup
{
public:
nsSchemaAttributeGroupRef(nsISchema* aSchema, const nsAReadableString& aRef);
virtual ~nsSchemaAttributeGroupRef();
NS_DECL_ISUPPORTS
NS_IMPL_NSISCHEMACOMPONENT_USING_BASE
NS_DECL_NSISCHEMAATTRIBUTECOMPONENT
NS_DECL_NSISCHEMAATTRIBUTEGROUP
protected:
nsString mRef;
nsCOMPtr<nsISchemaAttributeGroup> mAttributeGroup;
};
class nsSchemaAnyAttribute : public nsSchemaComponentBase,
public nsISchemaAnyAttribute
{
public:
nsSchemaAnyAttribute(nsISchema* aSchema);
virtual ~nsSchemaAnyAttribute();
NS_DECL_ISUPPORTS
NS_IMPL_NSISCHEMACOMPONENT_USING_BASE
NS_DECL_NSISCHEMAATTRIBUTECOMPONENT
NS_DECL_NSISCHEMAANYATTRIBUTE
NS_IMETHOD SetProcess(PRUint16 aProcess);
NS_IMETHOD SetNamespace(const nsAReadableString& aNamespace);
protected:
PRUint16 mProcess;
nsString mNamespace;
};
class nsSchemaFacet : public nsSchemaComponentBase,
public nsISchemaFacet
{
public:
nsSchemaFacet(nsISchema* aSchema, PRUint16 aFacetType, PRBool aIsFixed);
virtual ~nsSchemaFacet();
NS_DECL_ISUPPORTS
NS_IMPL_NSISCHEMACOMPONENT_USING_BASE
NS_DECL_NSISCHEMAFACET
NS_IMETHOD SetValue(const nsAReadableString& aStrValue);
NS_IMETHOD SetDigitsValue(PRUint32 aDigitsValue);
NS_IMETHOD SetWhitespaceValue(PRUint16 aWhitespaceValue);
protected:
PRUint16 mFacetType;
PRPackedBool mIsFixed;
nsString mStrValue;
PRUint32 mDigitsValue;
PRUint16 mWhitespaceValue;
};
#endif // __nsSchemaPrivate_h__

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

@ -0,0 +1,746 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla.
*
* The Initial Developer of the Original Code is Netscape
* Communications. Portions created by Netscape Communications are
* Copyright (C) 2001 by Netscape Communications. All
* Rights Reserved.
*
* Contributor(s):
* Vidur Apparao <vidur@netscape.com> (original author)
*/
#include "nsSchemaPrivate.h"
////////////////////////////////////////////////////////////
//
// nsSchemaBuiltinType implementation
//
////////////////////////////////////////////////////////////
nsSchemaBuiltinType::nsSchemaBuiltinType(PRUint16 aBuiltinType)
: mBuiltinType(aBuiltinType)
{
NS_INIT_ISUPPORTS();
}
nsSchemaBuiltinType::~nsSchemaBuiltinType()
{
}
NS_IMPL_ISUPPORTS4(nsSchemaBuiltinType,
nsISchemaComponent,
nsISchemaType,
nsISchemaSimpleType,
nsISchemaBuiltinType)
/* readonly attribute wstring targetNamespace; */
NS_IMETHODIMP
nsSchemaBuiltinType::GetTargetNamespace(nsAWritableString& aTargetNamespace)
{
aTargetNamespace.Assign(NS_LITERAL_STRING("http://www.w3.org/2001/XMLSchema"));
return NS_OK;
}
/* void resolve (); */
NS_IMETHODIMP
nsSchemaBuiltinType::Resolve()
{
return NS_OK;
}
/* void clear (); */
NS_IMETHODIMP
nsSchemaBuiltinType::Clear()
{
return NS_OK;
}
/* readonly attribute wstring name; */
NS_IMETHODIMP
nsSchemaBuiltinType::GetName(nsAWritableString& aName)
{
switch(mBuiltinType) {
case BUILTIN_TYPE_URTYPE:
aName.Assign(NS_LITERAL_STRING("anyType"));
break;
case BUILTIN_TYPE_STRING:
aName.Assign(NS_LITERAL_STRING("string"));
break;
case BUILTIN_TYPE_NORMALIZED_STRING:
aName.Assign(NS_LITERAL_STRING("normalizedString"));
break;
case BUILTIN_TYPE_TOKEN:
aName.Assign(NS_LITERAL_STRING("token"));
break;
case BUILTIN_TYPE_BYTE:
aName.Assign(NS_LITERAL_STRING("byte"));
break;
case BUILTIN_TYPE_UNSIGNEDBYTE:
aName.Assign(NS_LITERAL_STRING("unsignedByte"));
break;
case BUILTIN_TYPE_BASE64BINARY:
aName.Assign(NS_LITERAL_STRING("base64Binary"));
break;
case BUILTIN_TYPE_HEXBINARY:
aName.Assign(NS_LITERAL_STRING("hexBinary"));
break;
case BUILTIN_TYPE_INTEGER:
aName.Assign(NS_LITERAL_STRING("integer"));
break;
case BUILTIN_TYPE_POSITIVEINTEGER:
aName.Assign(NS_LITERAL_STRING("positiveInteger"));
break;
case BUILTIN_TYPE_NEGATIVEINTEGER:
aName.Assign(NS_LITERAL_STRING("negativeInteger"));
break;
case BUILTIN_TYPE_NONNEGATIVEINTEGER:
aName.Assign(NS_LITERAL_STRING("nonNegativeInteger"));
break;
case BUILTIN_TYPE_NONPOSITIVEINTEGER:
aName.Assign(NS_LITERAL_STRING("nonpositiveInteger"));
break;
case BUILTIN_TYPE_INT:
aName.Assign(NS_LITERAL_STRING("int"));
break;
case BUILTIN_TYPE_UNSIGNEDINT:
aName.Assign(NS_LITERAL_STRING("unsignedInt"));
break;
case BUILTIN_TYPE_LONG:
aName.Assign(NS_LITERAL_STRING("long"));
break;
case BUILTIN_TYPE_UNSIGNEDLONG:
aName.Assign(NS_LITERAL_STRING("unsignedLong"));
break;
case BUILTIN_TYPE_SHORT:
aName.Assign(NS_LITERAL_STRING("short"));
break;
case BUILTIN_TYPE_UNSIGNEDSHORT:
aName.Assign(NS_LITERAL_STRING("unsignedShort"));
break;
case BUILTIN_TYPE_DECIMAL:
aName.Assign(NS_LITERAL_STRING("decimal"));
break;
case BUILTIN_TYPE_FLOAT:
aName.Assign(NS_LITERAL_STRING("float"));
break;
case BUILTIN_TYPE_DOUBLE:
aName.Assign(NS_LITERAL_STRING("double"));
break;
case BUILTIN_TYPE_BOOLEAN:
aName.Assign(NS_LITERAL_STRING("boolean"));
break;
case BUILTIN_TYPE_TIME:
aName.Assign(NS_LITERAL_STRING("time"));
break;
case BUILTIN_TYPE_DATETIME:
aName.Assign(NS_LITERAL_STRING("dateTime"));
break;
case BUILTIN_TYPE_DURATION:
aName.Assign(NS_LITERAL_STRING("duration"));
break;
case BUILTIN_TYPE_DATE:
aName.Assign(NS_LITERAL_STRING("date"));
break;
case BUILTIN_TYPE_GMONTH:
aName.Assign(NS_LITERAL_STRING("gMonth"));
break;
case BUILTIN_TYPE_GYEAR:
aName.Assign(NS_LITERAL_STRING("gYear"));
break;
case BUILTIN_TYPE_GYEARMONTH:
aName.Assign(NS_LITERAL_STRING("gYearMonth"));
break;
case BUILTIN_TYPE_GDAY:
aName.Assign(NS_LITERAL_STRING("gDay"));
break;
case BUILTIN_TYPE_GMONTHDAY:
aName.Assign(NS_LITERAL_STRING("gMonthDay"));
break;
case BUILTIN_TYPE_NAME:
aName.Assign(NS_LITERAL_STRING("name"));
break;
case BUILTIN_TYPE_QNAME:
aName.Assign(NS_LITERAL_STRING("QName"));
break;
case BUILTIN_TYPE_NCNAME:
aName.Assign(NS_LITERAL_STRING("NCName"));
break;
case BUILTIN_TYPE_ANYURI:
aName.Assign(NS_LITERAL_STRING("anyURI"));
break;
case BUILTIN_TYPE_LANGUAGE:
aName.Assign(NS_LITERAL_STRING("language"));
break;
case BUILTIN_TYPE_ID:
aName.Assign(NS_LITERAL_STRING("ID"));
break;
case BUILTIN_TYPE_IDREF:
aName.Assign(NS_LITERAL_STRING("IDREF"));
break;
case BUILTIN_TYPE_IDREFS:
aName.Assign(NS_LITERAL_STRING("IDREF"));
break;
case BUILTIN_TYPE_ENTITY:
aName.Assign(NS_LITERAL_STRING("ENTITY"));
break;
case BUILTIN_TYPE_ENTITIES:
aName.Assign(NS_LITERAL_STRING("ENTITIES"));
break;
case BUILTIN_TYPE_NOTATION:
aName.Assign(NS_LITERAL_STRING("NOTATION"));
break;
case BUILTIN_TYPE_NMTOKEN:
aName.Assign(NS_LITERAL_STRING("NMTOKEN"));
break;
case BUILTIN_TYPE_NMTOKENS:
aName.Assign(NS_LITERAL_STRING("NMTOKENS"));
break;
default:
NS_ERROR("Unknown builtin type!");
aName.Truncate();
}
return NS_OK;
}
/* readonly attribute unsigned short schemaType; */
NS_IMETHODIMP
nsSchemaBuiltinType::GetSchemaType(PRUint16 *aSchemaType)
{
NS_ENSURE_ARG_POINTER(aSchemaType);
*aSchemaType = nsISchemaType::SCHEMA_TYPE_SIMPLE;
return NS_OK;
}
/* readonly attribute unsigned short simpleType; */
NS_IMETHODIMP
nsSchemaBuiltinType::GetSimpleType(PRUint16 *aSimpleType)
{
NS_ENSURE_ARG_POINTER(aSimpleType);
*aSimpleType = nsISchemaSimpleType::SIMPLE_TYPE_BUILTIN;
return NS_OK;
}
/* readonly attribute unsigned short builtinType; */
NS_IMETHODIMP
nsSchemaBuiltinType::GetBuiltinType(PRUint16 *aBuiltinType)
{
NS_ENSURE_ARG_POINTER(aBuiltinType);
*aBuiltinType = mBuiltinType;
return NS_OK;
}
////////////////////////////////////////////////////////////
//
// nsSchemaListType implementation
//
////////////////////////////////////////////////////////////
nsSchemaListType::nsSchemaListType(nsISchema* aSchema,
const nsAReadableString& aName)
: nsSchemaComponentBase(aSchema), mName(aName)
{
NS_INIT_ISUPPORTS();
}
nsSchemaListType::~nsSchemaListType()
{
}
NS_IMPL_ISUPPORTS4(nsSchemaListType,
nsISchemaComponent,
nsISchemaType,
nsISchemaSimpleType,
nsISchemaListType)
/* void resolve (); */
NS_IMETHODIMP
nsSchemaListType::Resolve()
{
return NS_OK;
}
/* void clear (); */
NS_IMETHODIMP
nsSchemaListType::Clear()
{
if (mIsClearing) {
return NS_OK;
}
mIsClearing = PR_TRUE;
if (mListType) {
mListType->Clear();
mListType = nsnull;
}
mIsClearing = PR_FALSE;
return NS_OK;
}
/* readonly attribute wstring name; */
NS_IMETHODIMP
nsSchemaListType::GetName(nsAWritableString& aName)
{
aName.Assign(mName);
return NS_OK;
}
/* readonly attribute unsigned short schemaType; */
NS_IMETHODIMP
nsSchemaListType::GetSchemaType(PRUint16 *aSchemaType)
{
NS_ENSURE_ARG_POINTER(aSchemaType);
*aSchemaType = nsISchemaType::SCHEMA_TYPE_SIMPLE;
return NS_OK;
}
/* readonly attribute unsigned short simpleType; */
NS_IMETHODIMP
nsSchemaListType::GetSimpleType(PRUint16 *aSimpleType)
{
NS_ENSURE_ARG_POINTER(aSimpleType);
*aSimpleType = nsISchemaSimpleType::SIMPLE_TYPE_LIST;
return NS_OK;
}
/* readonly attribute nsISchemaSimpleType listType; */
NS_IMETHODIMP
nsSchemaListType::GetListType(nsISchemaSimpleType * *aListType)
{
NS_ENSURE_ARG_POINTER(aListType);
*aListType = mListType;
NS_IF_ADDREF(*aListType);
return NS_OK;
}
NS_IMETHODIMP
nsSchemaListType::SetListType(nsISchemaSimpleType* aListType)
{
mListType = aListType;
return NS_OK;
}
////////////////////////////////////////////////////////////
//
// nsSchemaUnionType implementation
//
////////////////////////////////////////////////////////////
nsSchemaUnionType::nsSchemaUnionType(nsISchema* aSchema,
const nsAReadableString& aName)
: nsSchemaComponentBase(aSchema), mName(aName)
{
NS_INIT_ISUPPORTS();
}
nsSchemaUnionType::~nsSchemaUnionType()
{
}
NS_IMPL_ISUPPORTS4(nsSchemaUnionType,
nsISchemaComponent,
nsISchemaType,
nsISchemaSimpleType,
nsISchemaUnionType)
/* void resolve (); */
NS_IMETHODIMP
nsSchemaUnionType::Resolve()
{
return NS_OK;
}
/* void clear (); */
NS_IMETHODIMP
nsSchemaUnionType::Clear()
{
if (mIsClearing) {
return NS_OK;
}
mIsClearing = PR_TRUE;
nsresult rv;
PRUint32 i, count;
mUnionTypes.Count(&count);
for (i = 0; i < count; i++) {
nsCOMPtr<nsISchemaSimpleType> type;
rv = mUnionTypes.QueryElementAt(i, NS_GET_IID(nsISchemaSimpleType),
getter_AddRefs(type));
if (NS_SUCCEEDED(rv)) {
type->Clear();
}
}
mUnionTypes.Clear();
mIsClearing = PR_FALSE;
return NS_OK;
}
/* readonly attribute wstring name; */
NS_IMETHODIMP
nsSchemaUnionType::GetName(nsAWritableString& aName)
{
aName.Assign(mName);
return NS_OK;
}
/* readonly attribute unsigned short schemaType; */
NS_IMETHODIMP
nsSchemaUnionType::GetSchemaType(PRUint16 *aSchemaType)
{
NS_ENSURE_ARG_POINTER(aSchemaType);
*aSchemaType = nsISchemaType::SCHEMA_TYPE_SIMPLE;
return NS_OK;
}
/* readonly attribute unsigned short simpleType; */
NS_IMETHODIMP
nsSchemaUnionType::GetSimpleType(PRUint16 *aSimpleType)
{
NS_ENSURE_ARG_POINTER(aSimpleType);
*aSimpleType = nsISchemaSimpleType::SIMPLE_TYPE_UNION;
return NS_OK;
}
/* readonly attribute PRUint32 unionTypeCount; */
NS_IMETHODIMP
nsSchemaUnionType::GetUnionTypeCount(PRUint32 *aUnionTypeCount)
{
NS_ENSURE_ARG_POINTER(aUnionTypeCount);
return mUnionTypes.Count(aUnionTypeCount);
}
/* nsISchemaSimpleType getUnionType (in PRUint32 index); */
NS_IMETHODIMP
nsSchemaUnionType::GetUnionType(PRUint32 index, nsISchemaSimpleType **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
return mUnionTypes.QueryElementAt(index, NS_GET_IID(nsISchemaSimpleType),
(void**)_retval);
}
NS_IMETHODIMP
nsSchemaUnionType::AddUnionType(nsISchemaSimpleType* aType)
{
NS_ENSURE_ARG(aType);
return mUnionTypes.AppendElement(aType);
}
////////////////////////////////////////////////////////////
//
// nsSchemaRestrictionType implementation
//
////////////////////////////////////////////////////////////
nsSchemaRestrictionType::nsSchemaRestrictionType(nsISchema* aSchema,
const nsAReadableString& aName)
: nsSchemaComponentBase(aSchema), mName(aName)
{
NS_INIT_ISUPPORTS();
}
nsSchemaRestrictionType::~nsSchemaRestrictionType()
{
}
NS_IMPL_ISUPPORTS4(nsSchemaRestrictionType,
nsISchemaComponent,
nsISchemaType,
nsISchemaSimpleType,
nsISchemaRestrictionType)
/* void resolve (); */
NS_IMETHODIMP
nsSchemaRestrictionType::Resolve()
{
return NS_OK;
}
/* void clear (); */
NS_IMETHODIMP
nsSchemaRestrictionType::Clear()
{
if (mIsClearing) {
return NS_OK;
}
mIsClearing = PR_TRUE;
if (mBaseType) {
mBaseType->Clear();
mBaseType = nsnull;
}
nsresult rv;
PRUint32 i, count;
mFacets.Count(&count);
for (i = 0; i < count; i++) {
nsCOMPtr<nsISchemaFacet> facet;
rv = mFacets.QueryElementAt(i, NS_GET_IID(nsISchemaFacet),
getter_AddRefs(facet));
if (NS_SUCCEEDED(rv)) {
facet->Clear();
}
}
mFacets.Clear();
mIsClearing = PR_FALSE;
return NS_OK;
}
/* readonly attribute wstring name; */
NS_IMETHODIMP
nsSchemaRestrictionType::GetName(nsAWritableString& aName)
{
aName.Assign(mName);
return NS_OK;
}
/* readonly attribute unsigned short schemaType; */
NS_IMETHODIMP
nsSchemaRestrictionType::GetSchemaType(PRUint16 *aSchemaType)
{
NS_ENSURE_ARG_POINTER(aSchemaType);
*aSchemaType = nsISchemaType::SCHEMA_TYPE_SIMPLE;
return NS_OK;
}
/* readonly attribute unsigned short simpleType; */
NS_IMETHODIMP
nsSchemaRestrictionType::GetSimpleType(PRUint16 *aSimpleType)
{
NS_ENSURE_ARG_POINTER(aSimpleType);
*aSimpleType = nsISchemaSimpleType::SIMPLE_TYPE_RESTRICTION;
return NS_OK;
}
/* readonly attribute nsISchemaSimpleType baseType; */
NS_IMETHODIMP
nsSchemaRestrictionType::GetBaseType(nsISchemaSimpleType * *aBaseType)
{
NS_ENSURE_ARG_POINTER(aBaseType);
*aBaseType = mBaseType;
NS_IF_ADDREF(*aBaseType);
return NS_OK;
}
/* readonly attribute PRUint32 facetCount; */
NS_IMETHODIMP
nsSchemaRestrictionType::GetFacetCount(PRUint32 *aFacetCount)
{
NS_ENSURE_ARG_POINTER(aFacetCount);
return mFacets.Count(aFacetCount);
}
/* nsISchemaFacet getFacets (in PRUint32 index); */
NS_IMETHODIMP
nsSchemaRestrictionType::GetFacets(PRUint32 index, nsISchemaFacet **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
return mFacets.QueryElementAt(index, NS_GET_IID(nsISchemaFacet),
(void**)_retval);
}
NS_IMETHODIMP
nsSchemaRestrictionType::SetBaseType(nsISchemaSimpleType* aBaseType)
{
NS_ENSURE_ARG(aBaseType);
mBaseType = aBaseType;
return NS_OK;
}
NS_IMETHODIMP
nsSchemaRestrictionType::AddFacet(nsISchemaFacet* aFacet)
{
NS_ENSURE_ARG(aFacet);
return mFacets.AppendElement(aFacet);
}
/* End of implementation class template. */
////////////////////////////////////////////////////////////
//
// nsSchemaFacet implementation
//
////////////////////////////////////////////////////////////
nsSchemaFacet::nsSchemaFacet(nsISchema* aSchema,
PRUint16 aFacetType,
PRBool aIsFixed)
: nsSchemaComponentBase(aSchema), mFacetType(aFacetType), mIsFixed(aIsFixed)
{
NS_INIT_ISUPPORTS();
}
nsSchemaFacet::~nsSchemaFacet()
{
}
NS_IMPL_ISUPPORTS2(nsSchemaFacet,
nsISchemaComponent,
nsISchemaFacet)
/* void resolve (); */
NS_IMETHODIMP
nsSchemaFacet::Resolve()
{
return NS_OK;
}
/* void clear (); */
NS_IMETHODIMP
nsSchemaFacet::Clear()
{
return NS_OK;
}
/* readonly attribute unsigned short facetType; */
NS_IMETHODIMP
nsSchemaFacet::GetFacetType(PRUint16 *aFacetType)
{
NS_ENSURE_ARG_POINTER(aFacetType);
*aFacetType = mFacetType;
return NS_OK;
}
/* readonly attribute AString value; */
NS_IMETHODIMP
nsSchemaFacet::GetValue(nsAWritableString & aValue)
{
if ((mFacetType == FACET_TYPE_TOTALDIGITS) ||
(mFacetType == FACET_TYPE_FRACTIONDIGITS) ||
(mFacetType == FACET_TYPE_WHITESPACE)) {
return NS_ERROR_ILLEGAL_VALUE;
}
aValue.Assign(mStrValue);
return NS_OK;
}
/* readonly attribute PRUint32 digitsValue; */
NS_IMETHODIMP
nsSchemaFacet::GetDigitsValue(PRUint32 *aDigitsValue)
{
NS_ENSURE_ARG_POINTER(aDigitsValue);
if ((mFacetType != FACET_TYPE_TOTALDIGITS) &&
(mFacetType != FACET_TYPE_FRACTIONDIGITS)) {
return NS_ERROR_ILLEGAL_VALUE;
}
*aDigitsValue = mDigitsValue;
return NS_OK;
}
/* readonly attribute unsigned short whitespaceValue; */
NS_IMETHODIMP
nsSchemaFacet::GetWhitespaceValue(PRUint16 *aWhitespaceValue)
{
NS_ENSURE_ARG_POINTER(aWhitespaceValue);
if (mFacetType != FACET_TYPE_WHITESPACE) {
return NS_ERROR_ILLEGAL_VALUE;
}
*aWhitespaceValue = mWhitespaceValue;
return NS_OK;
}
/* readonly attribute boolean isfixed; */
NS_IMETHODIMP
nsSchemaFacet::GetIsfixed(PRBool *aIsFixed)
{
NS_ENSURE_ARG_POINTER(aIsFixed);
*aIsFixed = mIsFixed;
return NS_OK;
}
NS_IMETHODIMP
nsSchemaFacet::SetValue(const nsAReadableString& aStrValue)
{
if ((mFacetType == FACET_TYPE_TOTALDIGITS) ||
(mFacetType == FACET_TYPE_FRACTIONDIGITS) ||
(mFacetType == FACET_TYPE_WHITESPACE)) {
return NS_ERROR_ILLEGAL_VALUE;
}
mStrValue.Assign(aStrValue);
return NS_OK;
}
NS_IMETHODIMP
nsSchemaFacet::SetDigitsValue(PRUint32 aDigitsValue)
{
if ((mFacetType != FACET_TYPE_TOTALDIGITS) &&
(mFacetType != FACET_TYPE_FRACTIONDIGITS)) {
return NS_ERROR_ILLEGAL_VALUE;
}
mDigitsValue = aDigitsValue;
return NS_OK;
}
NS_IMETHODIMP
nsSchemaFacet::SetWhitespaceValue(PRUint16 aWhitespaceValue)
{
if (mFacetType != FACET_TYPE_WHITESPACE) {
return NS_ERROR_ILLEGAL_VALUE;
}
mWhitespaceValue = aWhitespaceValue;
return NS_OK;
}